Submission #475465

#TimeUsernameProblemLanguageResultExecution timeMemory
475465mosiashvililukaAddk (eJOI21_addk)C++14
100 / 100
137 ms4164 KiB
#include<bits/stdc++.h> using namespace std; long long a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,k,f[100009],fen[100009],fen2[100009],pas,tp,g[100009],l,r,m; void upd(long long q, long long w){ while(q<=100002){ fen[q]+=w; q=q+(q&(-q)); } } void upd2(long long q, long long w){ while(q<=100002){ fen2[q]+=w; q=q+(q&(-q)); } } long long read(long long q){ long long sm=0; while(q>0){ sm+=fen[q]; q=q-(q&(-q)); } return sm; } long long read2(long long q){ long long sm=0; while(q>0){ sm+=fen2[q]; q=q-(q&(-q)); } return sm; } long long calc(long long q, long long w){ if(q>w) return 0; long long sm=0; sm=read2(w)-read2(q-1);sm-=(read(w)-read(q-1))*(q-1); return sm; } long long calc2(long long q, long long w){ if(q>w) return 0; long long sm=0; sm=(read(w)-read(q-1))*(w-q+2)-calc(q,w); return sm; } int main(){ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>a>>k; for(i=1; i<=a; i++){ cin>>f[i]; upd(i,f[i]); upd2(i,i*f[i]); } cin>>tes; for(t=1; t<=tes; t++){ cin>>tp; if(tp==2){ cin>>l>>r>>m;pas=0; if(r-l+1>=2*m-2){ pas+=calc(l,l+m-2);i=l+m-1; pas+=calc2(r-m+2,r);j=r-m+1; if(j>=i){ pas+=(read(j)-read(i-1))*m; } }else{ pas+=calc(l,r-m);i=r-m+1; pas+=calc2(l+m,r);j=l+m-1; if(j>=i){ //pas+=(read(j)-read(i-1))*(r-m+1); pas+=(read(j)-read(i-1))*(r-m+1-l+1); } } cout<<pas<<"\n"; }else{ for(i=1; i<=k; i++){ cin>>g[i]; } for(i=1; i<=k; i++){ if(i==k) j=1; else j=i+1; upd(g[i],f[g[j]]-f[g[i]]); upd2(g[i],(f[g[j]]-f[g[i]])*g[i]); } for(i=1; i<k; i++) swap(f[g[i]],f[g[i+1]]); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...