#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
int P[200005], P2[200005], A[200005], S[200005];
void solve(){
int n, k;cin >> n >> k;
for(int i=1;i<=n;i++){
cin >> A[i];
P[i] = P[i-1] + A[i];
P2[i] = P2[i-1] + i*A[i];
}
for(int i=n;i>=1;i--){
S[i] = S[i+1] + A[i]*(n-i+1);
}
int q;cin >> q;
while(q--){
int x;cin >> x;
if(x == 1){
int p;cin >> p;
}
else{
int l,r,m;
cin >> l >> r >> m;
int tmp = (r-l+1);
m = min(m, tmp+1-m);
int ans = 0;
ans += P2[l+m-2] - P2[l-1] - (l-1)*(P[l+m-2] - P[l-1]);
ans += S[r-m+2] - S[r+1] - (n-r)*(P[r] - P[r-m+1]);
ans += m*(P[r-m+1] - P[l+m-2]);
cout << ans << '\n';
}
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message
Main.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
39 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
744 KB |
Output is correct |
9 |
Correct |
5 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1364 KB |
Output is correct |
2 |
Correct |
16 ms |
2388 KB |
Output is correct |
3 |
Correct |
20 ms |
3096 KB |
Output is correct |
4 |
Correct |
36 ms |
5316 KB |
Output is correct |
5 |
Correct |
58 ms |
7528 KB |
Output is correct |
6 |
Correct |
66 ms |
7160 KB |
Output is correct |
7 |
Correct |
47 ms |
7116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |