結果
問題 | No.1300 Sum of Inversions |
ユーザー | 👑Zack Ni |
提出日時 | 2020-11-30 14:03:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 349 ms / 2,000 ms |
コード長 | 2,246 bytes |
コンパイル時間 | 911 ms |
コンパイル使用メモリ | 89,216 KB |
実行使用メモリ | 15,064 KB |
最終ジャッジ日時 | 2024-09-13 02:21:08 |
合計ジャッジ時間 | 10,096 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 254 ms
12,244 KB |
testcase_04 | AC | 236 ms
11,988 KB |
testcase_05 | AC | 186 ms
10,580 KB |
testcase_06 | AC | 286 ms
13,488 KB |
testcase_07 | AC | 276 ms
12,888 KB |
testcase_08 | AC | 303 ms
14,036 KB |
testcase_09 | AC | 320 ms
13,776 KB |
testcase_10 | AC | 151 ms
9,304 KB |
testcase_11 | AC | 150 ms
9,300 KB |
testcase_12 | AC | 243 ms
12,116 KB |
testcase_13 | AC | 239 ms
11,860 KB |
testcase_14 | AC | 349 ms
14,732 KB |
testcase_15 | AC | 316 ms
13,784 KB |
testcase_16 | AC | 264 ms
12,500 KB |
testcase_17 | AC | 147 ms
9,044 KB |
testcase_18 | AC | 172 ms
9,940 KB |
testcase_19 | AC | 214 ms
11,092 KB |
testcase_20 | AC | 222 ms
11,224 KB |
testcase_21 | AC | 217 ms
11,220 KB |
testcase_22 | AC | 189 ms
10,448 KB |
testcase_23 | AC | 291 ms
13,264 KB |
testcase_24 | AC | 195 ms
10,580 KB |
testcase_25 | AC | 165 ms
9,680 KB |
testcase_26 | AC | 159 ms
9,560 KB |
testcase_27 | AC | 185 ms
10,324 KB |
testcase_28 | AC | 330 ms
14,164 KB |
testcase_29 | AC | 213 ms
11,220 KB |
testcase_30 | AC | 307 ms
13,836 KB |
testcase_31 | AC | 194 ms
10,708 KB |
testcase_32 | AC | 201 ms
10,964 KB |
testcase_33 | AC | 71 ms
12,648 KB |
testcase_34 | AC | 127 ms
12,780 KB |
testcase_35 | AC | 197 ms
15,064 KB |
testcase_36 | AC | 218 ms
14,928 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <map> using namespace std; int lsb(int x){ return x & (-x); } typedef long long ll; #define MODX 998244353 class FenwickTree{ public: ll * B; int n; FenwickTree(int n){ this->n = n; this->B = new ll[n+3]; for(int i = 0; i <= n+1; ++i) this->B[i] = 0; } ll getsum(int index){ ll sum = 0; index = index + 1; while(index > 0){ sum = (this->B[index] + sum) % MODX; index -= lsb(index); } return sum; } void update(int index, ll val){ index = index + 1; while(index <= n){ this->B[index] = (this->B[index] + val ) %MODX; index += lsb(index); } } }; ll add(ll x, ll y){ return (x+y)%MODX; } ll mul(ll x, ll y){ return (x*y)%MODX; } void CoordinateCompress(vector<int> u, vector<int> & v){ sort(u.begin(),u.end()); map<int,int> mpitoind; int n = u.size(); for(int i = 0; i< n; ++i) mpitoind[u[i]] = i; for(int i = 0; i < n; ++i) v[i] = mpitoind[v[i]]; } int main() { int n; cin >> n; vector<int> a; vector<int> b; for(int i = 0; i< n; ++i){ int x; cin >> x; a.push_back(x); b.push_back(x); } CoordinateCompress(a,a); FenwickTree * presum = new FenwickTree(n+2); FenwickTree * f = new FenwickTree(n+2); FenwickTree * g = new FenwickTree(n+2); FenwickTree * c = new FenwickTree(n+2); FenwickTree * gp = new FenwickTree(n+2); for(int i = n-1; i >= 0; --i){ ll nf = 1, ng = 0, nc = 0, ngp = 0; if(a[i] - 1 >= 0){ ll frequency = f->getsum(a[i]-1); ll pres = presum->getsum(a[i]-1); ng = add( mul(frequency, b[i]) , pres); nc = frequency; ll frequency2 = c->getsum(a[i]-1); ll pres2 = g->getsum(a[i]-1); ngp = add( mul(frequency2, b[i]) , pres2); } presum->update(a[i], b[i]); f->update(a[i], nf); g->update(a[i], ng); c->update(a[i], nc); gp->update(a[i], ngp); } cout << gp->getsum(n); return 0; }