#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t, n, q, a[N], tree[N];
void upd(int ind,int val) {
for(ind;ind <= n; ind += ind & (-ind)) tree[ind] += val;
}
int get(int ind) {
int ans = 0;
for(ind; ind >= 1; ind -= (ind) & (-ind)) ans += tree[ind];
return ans;
}
main(){
int K;
cin >> n >> K;
if(K > 1) return 0;
for(int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1], upd(i,a[i]);
int q;
cin >> q;
while(q--) {
int t;
cin >> t;
if(t == 1) {
int x;
cin >> x;
continue;
}
int l,r,m;
cin >> l >> r >> m;
cout << get(r) - get(l + m - 2) - (get(r - m) - get(l - 2)) << endl;
}
}
Compilation message
Main.cpp: In function 'void upd(long long int, long long int)':
Main.cpp:10:6: warning: statement has no effect [-Wunused-value]
10 | for(ind;ind <= n; ind += ind & (-ind)) tree[ind] += val;
| ^~~
Main.cpp: In function 'long long int get(long long int)':
Main.cpp:14:6: warning: statement has no effect [-Wunused-value]
14 | for(ind; ind >= 1; ind -= (ind) & (-ind)) ans += tree[ind];
| ^~~
Main.cpp: At global scope:
Main.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
17 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
332 KB |
Output is correct |
4 |
Correct |
10 ms |
424 KB |
Output is correct |
5 |
Correct |
13 ms |
460 KB |
Output is correct |
6 |
Correct |
16 ms |
432 KB |
Output is correct |
7 |
Correct |
19 ms |
556 KB |
Output is correct |
8 |
Correct |
22 ms |
584 KB |
Output is correct |
9 |
Correct |
30 ms |
664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
988 KB |
Output is correct |
2 |
Correct |
101 ms |
1516 KB |
Output is correct |
3 |
Correct |
129 ms |
2312 KB |
Output is correct |
4 |
Correct |
219 ms |
3360 KB |
Output is correct |
5 |
Correct |
317 ms |
5792 KB |
Output is correct |
6 |
Correct |
296 ms |
5576 KB |
Output is correct |
7 |
Correct |
299 ms |
5572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |