結果

問題 No.694 square1001 and Permutation 3
ユーザー square1001square1001
提出日時 2018-02-03 20:19:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 3,000 ms
コード長 636 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 47,096 KB
実行使用メモリ 10,804 KB
最終ジャッジ日時 2023-09-12 15:57:52
合計ジャッジ時間 5,552 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,136 KB
testcase_01 AC 2 ms
7,084 KB
testcase_02 AC 2 ms
7,080 KB
testcase_03 AC 3 ms
7,080 KB
testcase_04 AC 3 ms
7,124 KB
testcase_05 AC 2 ms
7,096 KB
testcase_06 AC 2 ms
7,080 KB
testcase_07 AC 202 ms
10,748 KB
testcase_08 AC 380 ms
10,720 KB
testcase_09 AC 383 ms
10,804 KB
testcase_10 AC 139 ms
10,772 KB
testcase_11 AC 381 ms
10,776 KB
testcase_12 AC 385 ms
10,784 KB
testcase_13 AC 2 ms
7,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[500009], p[500009], v[500009], bit[500009]; long long val;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]), p[i] = i, v[i] = a[i];
	sort(p, p + n, [](int i, int j) { return a[i] != a[j] ? a[i] > a[j] : i > j; });
	sort(v, v + n);
	for (int i = 0; i < n; i++) {
		for (int j = p[i]; j >= 1; j -= j & (-j)) val += bit[j];
		for (int j = p[i] + 1; j <= n; j += j & (-j)) bit[j]++;
	}
	for (int i = 0; i < n; i++) {
		printf("%lld\n", val);
		val += n - (lower_bound(v, v + n, a[i]) - v) - (upper_bound(v, v + n, a[i]) - v);
	}
	return 0;
}
0