#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e5 + 1;
long long n, k, a[maxn], p[maxn];
long long t[4 * maxn];
void make_tree(int i, int l, int r){
if(l == r){
t[i] = a[r];
return;
}
int mid = (l + r) / 2;
make_tree(2 * i, l, mid);
make_tree(2 * i + 1, mid + 1, r);
t[i] = t[2 * i] + t[2 * i + 1];
}
long long query(int i, int l, int r, int ql, int qr){
if(l == ql && r == qr){
return t[i];
}
int mid = (l + r) / 2;
if(qr <= mid) return query(2 * i, l, mid, ql ,qr);
if(ql > mid) return query(2 * i + 1, mid + 1, r, ql, qr);
return query(2 * i, l, mid, ql, mid) + query(2 * i + 1, mid + 1, r, mid + 1, qr);
}
void solve(){
int q;
cin >> q;
while(q--){
int type;
cin >> type;
if(type == 1){
for(int i = 0;i < k;i++){
int a;
cin >> a;
}
continue;
}
int l, r, m;
cin >> l >> r >> m;
long long ans = 0;
for(int i = l + m - 1;i <= r;i++){
int br_seg = 0;
int br_left = min(i - l + 1, m - 1);
br_seg = min(br_left, r - i + 1);
ans += p[i] - p[i - m];
}
cout << ans << endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 1;i <= n;i++){
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
make_tree(1, 1, n);
solve();
return 0;
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:48:17: warning: variable 'br_seg' set but not used [-Wunused-but-set-variable]
48 | int br_seg = 0;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
500 KB |
Output is correct |
6 |
Correct |
11 ms |
596 KB |
Output is correct |
7 |
Correct |
11 ms |
596 KB |
Output is correct |
8 |
Correct |
15 ms |
624 KB |
Output is correct |
9 |
Correct |
29 ms |
812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
1356 KB |
Output is correct |
2 |
Correct |
242 ms |
1764 KB |
Output is correct |
3 |
Correct |
408 ms |
2528 KB |
Output is correct |
4 |
Correct |
1659 ms |
4540 KB |
Output is correct |
5 |
Execution timed out |
2085 ms |
6568 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
677 ms |
2588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |