結果
問題 | No.1300 Sum of Inversions |
ユーザー | uzzy |
提出日時 | 2020-11-27 23:01:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 97 ms / 2,000 ms |
コード長 | 2,246 bytes |
コンパイル時間 | 1,630 ms |
コンパイル使用メモリ | 171,644 KB |
実行使用メモリ | 20,680 KB |
最終ジャッジ日時 | 2024-07-26 19:18:49 |
合計ジャッジ時間 | 5,423 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
9,576 KB |
testcase_01 | AC | 4 ms
9,576 KB |
testcase_02 | AC | 4 ms
9,716 KB |
testcase_03 | AC | 74 ms
17,988 KB |
testcase_04 | AC | 74 ms
18,232 KB |
testcase_05 | AC | 58 ms
17,192 KB |
testcase_06 | AC | 86 ms
19,460 KB |
testcase_07 | AC | 80 ms
18,944 KB |
testcase_08 | AC | 89 ms
19,816 KB |
testcase_09 | AC | 88 ms
19,520 KB |
testcase_10 | AC | 49 ms
16,064 KB |
testcase_11 | AC | 49 ms
15,516 KB |
testcase_12 | AC | 74 ms
18,004 KB |
testcase_13 | AC | 72 ms
18,244 KB |
testcase_14 | AC | 97 ms
20,468 KB |
testcase_15 | AC | 91 ms
19,452 KB |
testcase_16 | AC | 76 ms
18,736 KB |
testcase_17 | AC | 47 ms
15,140 KB |
testcase_18 | AC | 54 ms
15,896 KB |
testcase_19 | AC | 64 ms
16,980 KB |
testcase_20 | AC | 65 ms
17,640 KB |
testcase_21 | AC | 65 ms
17,160 KB |
testcase_22 | AC | 57 ms
17,020 KB |
testcase_23 | AC | 83 ms
19,296 KB |
testcase_24 | AC | 62 ms
16,680 KB |
testcase_25 | AC | 54 ms
15,600 KB |
testcase_26 | AC | 52 ms
15,548 KB |
testcase_27 | AC | 60 ms
17,320 KB |
testcase_28 | AC | 95 ms
19,872 KB |
testcase_29 | AC | 68 ms
17,080 KB |
testcase_30 | AC | 86 ms
19,672 KB |
testcase_31 | AC | 60 ms
16,448 KB |
testcase_32 | AC | 61 ms
17,396 KB |
testcase_33 | AC | 43 ms
14,400 KB |
testcase_34 | AC | 54 ms
14,484 KB |
testcase_35 | AC | 55 ms
20,680 KB |
testcase_36 | AC | 58 ms
20,520 KB |
ソースコード
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int mod = 998244353; const int bm = 200201; ll BIT00[bm], BIT01[bm], BIT10[bm], BIT11[bm]; void add00(int A) { while (A <= bm) { BIT00[A]++; A += A & -A; } } int query00(int A) { int ret = 0; while (A > 0) { ret += BIT00[A]; A -= A & -A; } return ret; } void add01(int A, ll B) { while (A <= bm) { BIT01[A] += B; A += A & -A; } } ll query01(int A) { ll ret = 0; while (A > 0) { ret += BIT01[A]; A -= A & -A; } return ret; } void add10(int A) { while (A > 0) { BIT10[A]++; A -= A & -A; } } int query10(int A) { int ret = 0; while (A <= bm) { ret += BIT10[A]; A += A & -A; } return ret; } void add11(int A, ll B) { while (A > 0) { BIT11[A] += B; A -= A & -A; } } ll query11(int A) { ll ret = 0; while (A <= bm) { ret += BIT11[A]; A += A & -A; } return ret; } void zaatu(int N, ll A[]) { ll tmp[200000]; rep(i, N) tmp[i] = A[i]; sort(tmp, tmp + N); rep(i, N) A[i] = lower_bound(tmp, tmp + N, A[i]) - tmp + 1; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; ll A[200000], B[200000]; rep(i, N) { cin >> A[i]; B[i] = A[i]; } zaatu(N, A); ll amae[200000], bmae[200000], aato[200000], bato[200000]; rep(i, N) { amae[i] = query10(A[i] + 2); bmae[i] = query11(A[i] + 2); add10(A[i] + 1); add11(A[i] + 1, B[i]); } for (int i = N - 1; i >= 0; i--) { aato[i] = query00(A[i] + 1); bato[i] = query01(A[i] + 1); add00(A[i] + 2); add01(A[i] + 2, B[i]); } ll kotae = 0; rep(i, N) { kotae += B[i] * amae[i] % mod * aato[i] % mod; kotae += bmae[i] % mod * aato[i] % mod; kotae += bato[i] % mod * amae[i] % mod; } co(kotae% mod); Would you please return 0; }