結果
問題 | No.1300 Sum of Inversions |
ユーザー |
![]() |
提出日時 | 2020-11-27 21:33:54 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,660 bytes |
コンパイル時間 | 1,731 ms |
コンパイル使用メモリ | 182,612 KB |
実行使用メモリ | 25,204 KB |
最終ジャッジ日時 | 2023-10-01 04:58:00 |
合計ジャッジ時間 | 10,468 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 232 ms
20,076 KB |
testcase_04 | AC | 228 ms
19,360 KB |
testcase_05 | AC | 184 ms
16,764 KB |
testcase_06 | AC | 269 ms
22,020 KB |
testcase_07 | AC | 256 ms
21,000 KB |
testcase_08 | AC | 287 ms
22,920 KB |
testcase_09 | AC | 279 ms
22,792 KB |
testcase_10 | AC | 144 ms
14,388 KB |
testcase_11 | AC | 148 ms
14,340 KB |
testcase_12 | AC | 231 ms
19,360 KB |
testcase_13 | AC | 227 ms
19,152 KB |
testcase_14 | WA | - |
testcase_15 | AC | 283 ms
22,800 KB |
testcase_16 | AC | 240 ms
20,256 KB |
testcase_17 | AC | 138 ms
13,828 KB |
testcase_18 | AC | 167 ms
15,560 KB |
testcase_19 | AC | 199 ms
17,876 KB |
testcase_20 | AC | 208 ms
18,204 KB |
testcase_21 | AC | 198 ms
18,140 KB |
testcase_22 | AC | 182 ms
16,452 KB |
testcase_23 | AC | 263 ms
21,792 KB |
testcase_24 | AC | 188 ms
17,044 KB |
testcase_25 | AC | 153 ms
15,192 KB |
testcase_26 | AC | 152 ms
14,912 KB |
testcase_27 | AC | 174 ms
16,244 KB |
testcase_28 | WA | - |
testcase_29 | AC | 195 ms
17,940 KB |
testcase_30 | AC | 277 ms
22,948 KB |
testcase_31 | AC | 179 ms
16,736 KB |
testcase_32 | AC | 193 ms
17,244 KB |
testcase_33 | AC | 41 ms
9,396 KB |
testcase_34 | AC | 89 ms
9,432 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; struct binary_indexed_tree{ int N; vector<long long> BIT; binary_indexed_tree(int N): N(N){ BIT = vector<long long>(N + 1, 0); } void add(int i, long long x){ i++; while (i <= N){ BIT[i] += x; BIT[i] %= MOD; i += i & -i; } } long long sum(int i){ long long ans = 0; while (i > 0){ ans += BIT[i]; ans %= MOD; i -= i & -i; } return ans; } long long sum(int L, int R){ return (sum(R) - sum(L) + MOD) % MOD; } }; int main(){ int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector<int> A2 = A; sort(A2.begin(), A2.end()); A2.erase(unique(A2.begin(), A2.end()), A2.end()); int cnt = A2.size(); map<int, int> mp; for (int i = 0; i < cnt; i++){ mp[A2[i]] = i; } for (int i = 0; i < N; i++){ A[i] = mp[A[i]]; } vector<long long> F(N, 0); vector<int> Fc(N, 0); binary_indexed_tree BIT1(cnt); binary_indexed_tree BIT2(cnt); for (int i = 0; i < N; i++){ F[i] = BIT1.sum(A[i] + 1, cnt); Fc[i] = BIT2.sum(A[i] + 1, cnt); BIT1.add(A[i], A2[A[i]]); BIT2.add(A[i], 1); } vector<long long> B(N, 0); vector<int> Bc(N, 0); binary_indexed_tree BIT3(cnt); binary_indexed_tree BIT4(cnt); for (int i = N - 1; i >= 0; i--){ B[i] = BIT3.sum(A[i]); Bc[i] = BIT4.sum(A[i]); BIT3.add(A[i], A2[A[i]]); BIT4.add(A[i], 1); } long long ans = 0; for (int i = 0; i < N; i++){ ans += F[i] * Bc[i] + B[i] * Fc[i] + Bc[i] * Fc[i] % MOD * A2[A[i]]; ans %= MOD; } cout << ans << endl; }