#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const long long maxn=1e5+5;
long long n,k,q;
long long a[maxn],b[32];
long long tree[4*maxn];
long long ql,qr;
void make_tree(long long v, long long l, long long r)
{
if(l==r)
{
tree[v]=a[r];
return;
}
long long mid=(l+r)/2;
make_tree(v*2,l,mid);
make_tree(v*2+1,mid+1,r);
tree[v]=tree[v*2]+tree[v*2+1];
}
long long query(long long v, long long l, long long r)
{
if(r<ql||l>qr||l>r) return 0;
if(l>=ql&&r<=qr) return tree[v];
long long mid=(l+r)/2;
return query(v*2,l,mid)+query(v*2+1,mid+1,r);
}
void read()
{
cin >> n >> k;
for(long long i=1;i<=n;i++)
{
cin >> a[i];
}
cin >> q;
make_tree(1,1,n);
long long ty,l,r,m;
for(long long i=1;i<=q;i++)
{
cin >> ty;
if(ty==1)
{
cin >> b[1];
}
else
{
cin >> l >> r >> m;
long long sum=0;
long long ch=0;
long long j=l;
long long z=l+m-1;
for(int q=j;q<=z;q++)
{
ch+=a[q];
}
sum+=ch;
z++;
j++;
for(z;z<=r;z++)
{
ch-=a[j-1];
ch+=a[z];
sum+=ch;
j++;
}
cout << sum << endl;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
read();
return 0;
}
/*
8 1
7 2 5 1 9 3 4 6
8
2 2 7 4
2 2 7 3
2 1 8 5
2 3 8 2
2 5 6 8
2 2 8 3
2 3 6 1
2 1 4 2
*/
Compilation message
Main.cpp: In function 'void read()':
Main.cpp:63:17: warning: statement has no effect [-Wunused-value]
63 | for(z;z<=r;z++)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
444 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
9 ms |
560 KB |
Output is correct |
6 |
Correct |
13 ms |
632 KB |
Output is correct |
7 |
Correct |
19 ms |
664 KB |
Output is correct |
8 |
Correct |
24 ms |
708 KB |
Output is correct |
9 |
Correct |
48 ms |
1008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
1204 KB |
Output is correct |
2 |
Correct |
368 ms |
2116 KB |
Output is correct |
3 |
Correct |
658 ms |
3200 KB |
Output is correct |
4 |
Execution timed out |
2060 ms |
5648 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
779 ms |
2232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |