結果
問題 | No.1300 Sum of Inversions |
ユーザー | kotatsugame |
提出日時 | 2020-11-28 03:50:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 349 ms / 2,000 ms |
コード長 | 3,986 bytes |
コンパイル時間 | 1,142 ms |
コンパイル使用メモリ | 93,300 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2024-09-12 21:56:22 |
合計ジャッジ時間 | 10,846 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 3 ms
6,944 KB |
testcase_03 | AC | 255 ms
12,672 KB |
testcase_04 | AC | 244 ms
12,544 KB |
testcase_05 | AC | 195 ms
8,320 KB |
testcase_06 | AC | 296 ms
12,800 KB |
testcase_07 | AC | 271 ms
12,672 KB |
testcase_08 | AC | 310 ms
12,800 KB |
testcase_09 | AC | 306 ms
12,800 KB |
testcase_10 | AC | 161 ms
8,320 KB |
testcase_11 | AC | 164 ms
8,192 KB |
testcase_12 | AC | 248 ms
12,544 KB |
testcase_13 | AC | 240 ms
12,544 KB |
testcase_14 | AC | 349 ms
12,928 KB |
testcase_15 | AC | 300 ms
12,800 KB |
testcase_16 | AC | 260 ms
12,672 KB |
testcase_17 | AC | 151 ms
8,064 KB |
testcase_18 | AC | 175 ms
8,192 KB |
testcase_19 | AC | 218 ms
12,416 KB |
testcase_20 | AC | 225 ms
12,544 KB |
testcase_21 | AC | 214 ms
12,672 KB |
testcase_22 | AC | 201 ms
8,320 KB |
testcase_23 | AC | 289 ms
12,800 KB |
testcase_24 | AC | 201 ms
8,320 KB |
testcase_25 | AC | 169 ms
8,192 KB |
testcase_26 | AC | 166 ms
8,192 KB |
testcase_27 | AC | 187 ms
8,448 KB |
testcase_28 | AC | 319 ms
12,928 KB |
testcase_29 | AC | 216 ms
12,416 KB |
testcase_30 | AC | 305 ms
12,800 KB |
testcase_31 | AC | 200 ms
8,320 KB |
testcase_32 | AC | 209 ms
8,320 KB |
testcase_33 | AC | 204 ms
12,928 KB |
testcase_34 | AC | 260 ms
12,928 KB |
testcase_35 | AC | 229 ms
12,928 KB |
testcase_36 | AC | 252 ms
12,928 KB |
コンパイルメッセージ
a.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp" #include<iostream> #include<vector> #include<algorithm> using namespace std; #line 3 "/home/kotatsugame/library/math/modint.cpp" #include<utility> template<int m> struct modint{ unsigned int x; constexpr modint()noexcept:x(){} template<typename T> constexpr modint(T x_)noexcept:x((x_%=m)<0?x_+m:x_){} constexpr unsigned int val()const noexcept{return x;} constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;} constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;} constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;} constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;} constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;} constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;} constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;} constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();} constexpr modint operator+()const noexcept{return*this;} constexpr modint operator-()const noexcept{return modint()-*this;} constexpr modint pow(long long n)const noexcept { if(n<0)return pow(-n).inv(); modint x=*this,r=1; for(;n;x*=x,n>>=1)if(n&1)r*=x; return r; } constexpr modint inv()const noexcept { int s=x,t=m,x=1,u=0; while(t) { int k=s/t; s-=k*t; swap(s,t); x-=k*u; swap(x,u); } return modint(x); } friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;} friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;} friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;} friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;} friend constexpr bool operator==(const modint&a,const modint&b){return a.x==b.x;} friend constexpr bool operator!=(const modint&a,const modint&b){return a.x!=b.x;} friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;} friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;} }; #line 2 "/home/kotatsugame/library/datastructure/segtree.cpp" #include<functional> #include<limits> template<typename T> struct segtree{ using F=function<T(T,T)>; const F calcfn,updatefn; int n; T defvalue; vector<T>dat; segtree(int n_=0,T defvalue_=numeric_limits<T>::max(), const F calcfn_=[](T a,T b){return a<b?a:b;}, const F updatefn_=[](T a,T b){return b;} ):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_) { n=1; while(n<n_)n<<=1; dat.assign(2*n-1,defvalue); } void copy(const vector<T>&v) { for(int i=0;i<v.size();i++)dat[i+n-1]=v[i]; for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]); } void update(int i,T a) { i+=n-1; dat[i]=updatefn(dat[i],a); while(i>0) { i=(i-1)/2; dat[i]=calcfn(dat[2*i+1],dat[2*i+2]); } } T query(int a,int b)//[a,b) { int L=(a<0?0:a>n?n:a)+n-1; int R=(b<0?0:b>n?n:b)+n-1; T lret=defvalue,rret=defvalue; for(;L<R;L>>=1,R>>=1) { if(!(L&1))lret=calcfn(lret,dat[L]); if(!(R&1))rret=calcfn(dat[--R],rret); } return calcfn(lret,rret); } }; #line 7 "a.cpp" using mint=modint<998244353>; int N; main() { cin>>N; vector<pair<int,int> >A(N); for(int i=0;i<N;i++) { cin>>A[i].first; A[i].second=i; } sort(A.begin(),A.end()); segtree<mint>V1(N,0,[](mint a,mint b){return a+b;},[](mint a,mint b){return b;}); segtree<mint>V2(N,0,[](mint a,mint b){return a+b;},[](mint a,mint b){return b;}); segtree<mint>C1(N,0,[](mint a,mint b){return a+b;},[](mint a,mint b){return b;}); segtree<mint>C2(N,0,[](mint a,mint b){return a+b;},[](mint a,mint b){return b;}); mint ans; for(int i=N;i--;) { int id=A[i].second; mint a=A[i].first; ans+=V2.query(0,id)+C2.query(0,id)*a; V2.update(id,V1.query(0,id)+C1.query(0,id)*a); C2.update(id,C1.query(0,id)); V1.update(id,a); C1.update(id,1); } cout<<ans<<endl; }