結果

問題 No.1300 Sum of Inversions
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-01 02:34:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 894 bytes
コンパイル時間 8,935 ms
コンパイル使用メモリ 221,444 KB
実行使用メモリ 32,256 KB
最終ジャッジ日時 2024-04-01 02:34:44
合計ジャッジ時間 32,662 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 39 ms
6,676 KB
testcase_34 AC 94 ms
6,676 KB
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/fenwicktree>
#include <atcoder/modint>
using namespace atcoder;
using namespace std;
using ll = long long;
using mint = modint998244353;
int main() {
	int N;cin >> N;
	set<ll> value;
	vector<ll> A(N + 1, 0);
	for (int i = 1;i <= N;i++) {
		cin >> A[i];
		value.insert(A[i]);
	}
	map<ll, int> tos;
	int K = 0;
	for (auto v : value) {
		tos[v] = K +1;
		K++;
	}
	fenwick_tree<mint> bits(K + 10);
	fenwick_tree<mint> bits2(K + 10);
	fenwick_tree<ll> cnt(K + 10);
	fenwick_tree<ll> cnt2(K + 10);
	vector<mint> T(N + 1, 0);
	mint ans = 0;
	for (int i = N;i >= 1;i--) {
		int now = tos[A[i]];
		T[i] = (A[i] * cnt.sum(0, now)) + bits.sum(0, now);
		bits.add(now, A[i]);
		ans += bits2.sum(0, now) + (A[i] * cnt2.sum(0, now));
		bits2.add(now, T[i]);
		cnt.add(now, 1);
		if (cnt.sum(0, now) != 0) {
			cnt2.add(now, 1);
		}
	}
	cout << ans.val() << endl;
}
0