結果
問題 | No.1300 Sum of Inversions |
ユーザー | ysystem7 |
提出日時 | 2020-11-27 21:58:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,847 bytes |
コンパイル時間 | 3,493 ms |
コンパイル使用メモリ | 226,440 KB |
実行使用メモリ | 42,880 KB |
最終ジャッジ日時 | 2023-10-01 05:44:19 |
合計ジャッジ時間 | 24,587 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 665 ms
37,620 KB |
testcase_04 | AC | 646 ms
37,320 KB |
testcase_05 | AC | 522 ms
25,736 KB |
testcase_06 | AC | 826 ms
39,660 KB |
testcase_07 | AC | 727 ms
38,884 KB |
testcase_08 | AC | 842 ms
40,864 KB |
testcase_09 | AC | 836 ms
40,708 KB |
testcase_10 | AC | 421 ms
23,496 KB |
testcase_11 | AC | 418 ms
23,688 KB |
testcase_12 | AC | 702 ms
37,032 KB |
testcase_13 | AC | 631 ms
36,888 KB |
testcase_14 | AC | 992 ms
42,696 KB |
testcase_15 | AC | 844 ms
40,648 KB |
testcase_16 | AC | 736 ms
37,924 KB |
testcase_17 | AC | 386 ms
23,036 KB |
testcase_18 | AC | 424 ms
24,620 KB |
testcase_19 | AC | 586 ms
35,176 KB |
testcase_20 | AC | 609 ms
35,572 KB |
testcase_21 | AC | 570 ms
35,512 KB |
testcase_22 | AC | 502 ms
25,688 KB |
testcase_23 | AC | 822 ms
39,660 KB |
testcase_24 | AC | 528 ms
26,204 KB |
testcase_25 | AC | 472 ms
24,072 KB |
testcase_26 | AC | 409 ms
24,396 KB |
testcase_27 | AC | 475 ms
25,412 KB |
testcase_28 | AC | 842 ms
41,400 KB |
testcase_29 | AC | 546 ms
35,228 KB |
testcase_30 | AC | 828 ms
40,564 KB |
testcase_31 | AC | 507 ms
25,948 KB |
testcase_32 | AC | 532 ms
26,612 KB |
testcase_33 | AC | 19 ms
4,564 KB |
testcase_34 | AC | 33 ms
4,552 KB |
testcase_35 | AC | 369 ms
42,828 KB |
testcase_36 | WA | - |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(),(v).end() #define LB(a,x) lb(all(a),x)-a.begin() #define UB(a,x) ub(all(a),x)-a.begin() //#define mod 1000000007 #define mod 998244353 #define FS fixed<<setprecision(15) using namespace std; typedef long long ll; const double pi=3.141592653589793; template<class T> using V=vector<T>; using Graph = vector<vector<int>>; using P=pair<ll,ll>; typedef unsigned long long ull; typedef long double ldouble; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline void out(T a){ cout << a << '\n'; } void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;} //void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;} const ll INF=1e18; const int mx=200005; class Segtree{ public: ll N=1; V<ll> dat; explicit Segtree(ll sz){ while(N<sz) N*=2; dat.reserve(2*N); rep(i,2*N)dat[i]=0; } // Range Minimum Query ------------------------- void min_init(){ for(int i=0;i<N;i++)min_update(i,INF); } void min_update(ll k,ll a){ k+=N-1; dat[k]=a; while(k>0){ k=(k-1)/2; dat[k]=min(dat[2*k+1],dat[2*k+2]); } } ll min_query(ll a,ll b,ll k,ll l,ll r){ if(r<=a||b<=l)return INF; if(a<=l&&r<=b)return dat[k]; ll m=(l+r)/2; ll u=min_query(a,b,2*k+1,l,m); ll v=min_query(a,b,2*k+2,m,r); return min(u,v); } ll get_min(ll l,ll r){ return min_query(l,r,0,0,N); } //Range Maximum Query --------------------------- void max_init(){ for(int i=0;i<N;i++)max_update(i,-INF); } void max_update(ll k,ll a){ k+=N-1; dat[k]=a; while(k>0){ k=(k-1)/2; dat[k]=max(dat[2*k+1],dat[2*k+2]); } } ll max_query(ll a,ll b,ll k,ll l,ll r){ if(r<=a||b<=l)return -INF; if(a<=l&&r<=b)return dat[k]; ll m=(l+r)/2; ll u=max_query(a,b,2*k+1,l,m); ll v=max_query(a,b,2*k+2,m,r); return max(u,v); } ll get_max(ll l,ll r){ return max_query(l,r,0,0,N); } //Range Sum Query ----------------------------- void sum_update(ll k,ll a){ k+=N-1; dat[k]+=a; while(k>0){ k=(k-1)/2; dat[k]=(dat[2*k+1]+dat[2*k+2]); } } ll sum_query(ll a,ll b,ll k,ll l,ll r){ if(r<=a||b<=l)return 0LL; if(a<=l&&r<=b)return dat[k]; ll m=(l+r)/2; ll u=sum_query(a,b,2*k+1,l,m); ll v=sum_query(a,b,2*k+2,m,r); return (u+v); } ll get_sum(ll l,ll r){ return sum_query(l,r,0,0,N); } //その他---------------------------------------- /* ll unit(){ return ;//単位元 } ll calc(ll a,ll b){ return ;//演算 } void update(ll k,ll a){ k+=N-1; dat[k]=a; while(k>0){ k=(k-1)/2; dat[k]=calc(dat[2*k+1],dat[2*k+2]); } } ll query(ll a,ll b,ll k,ll l,ll r){ if(r<=a||b<=l)return unit(); if(a<=l&&r<=b)return dat[k]; ll m=(l+r)/2; ll u=query(a,b,2*k+1,l,m); ll v=query(a,b,2*k+2,m,r); return calc(u,v); } ll get_val(ll l,ll r){ return query(l,r,0,0,N); } */ }; int main(){ //オーバーフローは大丈夫ですか?? cin.tie(0);ios::sync_with_stdio(false); ll n; cin>>n; V<ll> a(n); set<ll> st; //Segtree slsum(n),slcnt(n) rep(i,n){ cin>>a[i]; st.insert(a[i]); } int sz=(int)st.size(); Segtree slsum(sz),slcnt(sz),srsum(sz),srcnt(sz); //V<ll> v; int pos=0; map<ll,ll> mp; for(ll p:st){ //v.pb(p); mp[p]=pos; pos++; } slsum.sum_update(mp[a[0]],a[0]); slcnt.sum_update(mp[a[0]],1); for(int i=1;i<n;i++){ srsum.sum_update(mp[a[i]],a[i]); srcnt.sum_update(mp[a[i]],1); } ll ans=0; for(int i=1;i<n-1;i++){ int p=mp[a[i]]; ll s=slcnt.get_sum(p+1,sz); ll t=srcnt.get_sum(0,p); ll ss=slsum.get_sum(p+1,sz); ll tt=srsum.get_sum(0,p); ans=(ans+a[i]*s%mod*t%mod)%mod; ans=(ans+ss*t%mod)%mod; ans=(ans+s*tt%mod)%mod; slcnt.sum_update(p,1); slsum.sum_update(p,a[i]); srcnt.sum_update(p,-1); srsum.sum_update(p,-a[i]); } out(ans); }