結果

問題 No.694 square1001 and Permutation 3
ユーザー e869120e869120
提出日時 2018-06-08 22:28:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 982 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 76,660 KB
実行使用メモリ 5,280 KB
最終ジャッジ日時 2023-09-12 23:55:15
合計ジャッジ時間 2,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int bit[200009]; vector<int>vec;

void add(int pos, int x) {
	pos++;
	while (pos <= 200007) { bit[pos] += x; pos += (pos&-pos); }
}
int sum(int pos) {
	pos++; int s = 0;
	while (pos >= 1) { s += bit[pos]; pos -= (pos&-pos); }
	return s;
}
int Sum(int L, int R) {
	return sum(R) - sum(L - 1);
}

int n, a[200009];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]); vec.push_back(a[i]);
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for (int i = 1; i <= n; i++) {
		a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();
	}

	long long V = 0;
	for (int i = 1; i <= n; i++) {
		V += Sum(a[i] + 1, vec.size());
		add(a[i], 1);
	}
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", V);
		add(a[i], -1);
		V -= Sum(0, a[i] - 1);
		V += Sum(a[i] + 1, vec.size());
		add(a[i], 1);
	}
	return 0;
}
0