This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
long long n,k;
long long a[10001];
long long t[40001];
long long p[10001];
void read()
{
cin>>n>>k;
for(long long i=1;i<=n;i++)
{cin>>a[i];p[i]=p[i-1]+a[i];}
}
void make_tree(long long i,long long l,long long r)
{
if(l>r)return;
if(l==r)
{
t[i]=a[l];
return;
}
long long 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];
}
long long query(long long i,long long l,long long r,long long ql,long long qr)
{
if(l>r||r<ql||l>qr)return 0;
if(l>=ql&&qr>=r)return t[i];
long long 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(long long i=1;i<=n*4;i++)
cout<<t[i]<<" ";
cout<<endl;
}
long long q;
void solve()
{
cin>>q;
for(long long i=1;i<=q;i++)
{
long long c;
cin>>c;
if(c==1)
{
long long help;
cin>>help;
}
else
{
long long ql,qr,m;
cin>>ql>>qr>>m;
long long ans=0;
for(long long 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |