Submission #583724

#TimeUsernameProblemLanguageResultExecution timeMemory
583724n3rm1nAddk (eJOI21_addk)C++17
0 / 100
5 ms596 KiB
#include<bits/stdc++.h> using namespace std; int n,k; int a[10001]; int t[40001]; int p[10001]; void read() { cin>>n>>k; for(int i=1;i<=n;i++) {cin>>a[i];p[i]=p[i-1]+a[i];} } void make_tree(int i,int l,int r) { if(l>r)return; if(l==r) { t[i]=a[l]; return; } int m=(l+r)/2; make_tree(i*2,l,m); make_tree(i*2+1,m+1,r); t[i]=t[i*2]+t[i*2+1]; } int query(int i,int l,int r,int ql,int qr) { if(l>r||r<ql||l>qr)return 0; if(l>=ql&&qr>=r)return t[i]; int m=(l+r)/2; return query(i*2,l,m,ql,m)+query(i*2+1,m+1,r,m+1,qr); } void test() { for(int i=1;i<=n*4;i++) cout<<t[i]<<" "; cout<<endl; } int q; void solve() { cin>>q; for(int i=1;i<=q;i++) { int c; cin>>c; if(c==1) { int help; cin>>help; } else { int ql,qr,m; cin>>ql>>qr>>m; int ans=0; for(int j=ql;j<=qr-m+1;j++) { ans+=p[j+m-1]-p[j-1]; //ans+=query(1,1,n,j,j+m-1); //cout<<j<<" "<<j+m-1<<" "<<query(1,1,n,j,j+m-1)<<"||"; } cout<<ans<<endl; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(); //make_tree(1,1,n); //test(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...