#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e5 + 1;
int 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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
8 ms |
456 KB |
Output is correct |
6 |
Incorrect |
9 ms |
468 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
109 ms |
1152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
694 ms |
2280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |