Submission #1035236

#TimeUsernameProblemLanguageResultExecution timeMemory
1035236devariaotaAddk (eJOI21_addk)C++17
0 / 100
36 ms1712 KiB
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n,k; cin>>n>>k; if(k==1){ int a[n+1]; for(int q=1;q<=n;q++){ cin>>a[q]; } int pref[n+1],suf[n+2],sum[n+1],blk[n+1]; pref[0]=0; suf[n+1]=0; sum[0]=0; blk[n+1]=0; for(int q=1;q<=n;q++){ pref[q]=pref[q-1]+q*a[q]; sum[q]=sum[q-1]+a[q]; } for(int q=n;q>=1;q--){ suf[q]=suf[q+1]+(n-q+1)*a[q]; blk[q]=blk[q+1]+a[q]; } int q; cin>>q; for(int w=1;w<=q;w++){ int type; cin>>type; if(type==1){ int r; cin>>r; } else{ int l,r,m; cin>>l>>r>>m; int ans=0; if((r-l+1)%2==0){ int posl=min(l-1+(r-l+1)/2,l+m-1); int posr=max(r+1-(r-l+1)/2,r-m+1); ans+=pref[posl]-pref[l-1]-(l-1)*(sum[posl]-sum[l-1]); ans+=suf[posr]-suf[r+1]-(n-r)*(blk[posr]-blk[r+1]); posl++; posr--; if(posl<=posr){ ans+=m*(sum[posr]-sum[posl-1]); } } else{ int posl=min(l+m-1,l-1+(r-l+1)/2); int posr=max(r-m+1,r+1-(r-l+1)/2); //cout<<posl<<" "<<posr<<endl; ans+=pref[posl]-pref[l-1]-(l-1)*(sum[posl]-sum[l-1]); ans+=suf[posr]-suf[r+1]-(n-r)*(blk[posr]-blk[r+1]); //cout<<ans<<endl; posl++; posr--; if(posl<=posr){ ans+=m*(sum[posr]-sum[posl-1]); } } cout<<ans<<endl; } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...