結果
問題 | No.1300 Sum of Inversions |
ユーザー | ocvret_ |
提出日時 | 2020-11-27 22:57:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,151 bytes |
コンパイル時間 | 1,914 ms |
コンパイル使用メモリ | 185,404 KB |
実行使用メモリ | 41,792 KB |
最終ジャッジ日時 | 2023-10-09 20:57:52 |
合計ジャッジ時間 | 18,333 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 503 ms
38,452 KB |
testcase_04 | AC | 482 ms
38,208 KB |
testcase_05 | AC | 382 ms
24,100 KB |
testcase_06 | AC | 567 ms
39,656 KB |
testcase_07 | AC | 539 ms
39,324 KB |
testcase_08 | AC | 604 ms
40,504 KB |
testcase_09 | AC | 595 ms
40,340 KB |
testcase_10 | AC | 308 ms
22,608 KB |
testcase_11 | AC | 315 ms
22,612 KB |
testcase_12 | AC | 489 ms
38,168 KB |
testcase_13 | AC | 473 ms
38,076 KB |
testcase_14 | AC | 663 ms
41,792 KB |
testcase_15 | AC | 594 ms
40,208 KB |
testcase_16 | AC | 507 ms
38,532 KB |
testcase_17 | AC | 291 ms
22,504 KB |
testcase_18 | AC | 353 ms
23,560 KB |
testcase_19 | AC | 433 ms
37,160 KB |
testcase_20 | AC | 432 ms
37,296 KB |
testcase_21 | AC | 429 ms
37,112 KB |
testcase_22 | AC | 386 ms
24,088 KB |
testcase_23 | AC | 553 ms
39,772 KB |
testcase_24 | AC | 395 ms
24,436 KB |
testcase_25 | AC | 336 ms
23,236 KB |
testcase_26 | AC | 322 ms
23,136 KB |
testcase_27 | AC | 364 ms
23,796 KB |
testcase_28 | AC | 621 ms
40,700 KB |
testcase_29 | AC | 436 ms
37,072 KB |
testcase_30 | AC | 596 ms
40,656 KB |
testcase_31 | AC | 377 ms
24,304 KB |
testcase_32 | AC | 404 ms
24,492 KB |
testcase_33 | AC | 43 ms
4,664 KB |
testcase_34 | AC | 94 ms
4,916 KB |
testcase_35 | AC | 353 ms
41,684 KB |
testcase_36 | WA | - |
ソースコード
#include<bits/stdc++.h> // #include<atcoder/all> using namespace std; // using namespace atcoder; using ll = long long; using ull = unsigned long long; using P = pair<int,int>; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 template<typename T> class Segtree{ public: using F = function<T(T,T)>; int n; F f; T ti; vector<T> dat; Segtree(){}; Segtree(F f,T ti): f(f),ti(ti){} void init(int N){ n = 1; while(n < N)n <<= 1; dat.assign(n << 1,ti); } void build(const vector<T> &v){ int N = v.size(); init(N); rep(i,N)dat[n+i] = v[i]; for(int i = n-1;i >= 0;i--)dat[i] = f(dat[(i << 1)|0],dat[(i << 1)|1]); } void set(int k,T x){ dat[k+=n] = x; while(k >>= 1){ dat[k] = f(dat[(k << 1)|0],dat[(k << 1)|1]); } } T get(int l,int r){ T vl = ti,vr = ti; for(l += n,r += n;l < r;l >>= 1,r >>= 1){ if(l & 1)vl = f(vl,dat[l++]); if(r & 1)vr = f(dat[--r],vr); } return f(vl,vr); } }; const int mod = 998244353; int main(){ int n; cin >> n; vector<int> v(n); vector<int> w(n); rep(i,n)cin >> v[i],w[i] = v[i]; sort(ALL(w)); w.erase(unique(ALL(w)),w.end()); map<int,int> mp; int m = w.size(); rep(i,m)mp[w[i]] = i; auto f = [&](pair<ll,ll> a,pair<ll,ll> b){return pair<ll,ll>{(a.first+b.first)%mod,a.second+b.second};}; Segtree<pair<ll,ll>> one(f,{0,0}),two(f,{0,0}),three(f,{0,0}); one.build(vector<pair<ll,ll>>(m,{0,0})); two.build(vector<pair<ll,ll>>(m,{0,0})); three.build(vector<pair<ll,ll>>(m,{0,0})); rep(i,n){ int k = mp[v[i]]; { pair<ll,ll> x = one.get(k,k+1); x.first += v[i];x.second++; x.first %= mod; one.set(k,x); } { pair<ll,ll> x = two.get(k,k+1); pair<ll,ll> y = one.get(k+1,m); two.set(k,{(x.first+y.first+y.second*v[i]%mod)%mod,x.second+y.second}); } { pair<ll,ll> x = three.get(k,k+1); pair<ll,ll> y = two.get(k+1,m); three.set(k,{(x.first+y.first+y.second*v[i]%mod)%mod,x.second+y.second}); } } cout << three.get(0,m).first << "\n"; return 0; }