This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int nmax = 1e5+5;
int A[nmax];
int pref[nmax]={0};
int segtree[4*nmax];
void build(int idx, int low, int high) {
if(low==high) {
segtree[idx] = A[low];
return;
}
int mid = (low+high)/2;
build(2*idx, low, mid);
build(2*idx+1, mid+1, high);
segtree[idx] = segtree[2*idx]+segtree[2*idx+1];
}
int query(int idx, int low, int high, int l, int r) {
if(low>=l && high<=r) {
return segtree[idx];
}
if(low>r || high<l) {
return 0;
}
int mid = (low+high)/2;
int left = query(2*idx,low,mid,l,r);
int right = query(2*idx+1,mid+1,high,l,r);
return left+right;
}
int main() {
int N,K,Q;
cin >> N >> K;
pref[0] = 0;
for(int i=1; i<=N; i++) {
cin >> A[i];
pref[i] = A[i]+pref[i-1];
}
//build(1,1,N);
cin >> Q;
int com,l,r,m;
int ujung, kal;
long long sem;
long long sum;
for(int i=1; i<=Q; i++) {
cin >> com;
sum = 0;
if(com==1) {
cin >> m;
} else {
cin >> l >> r >> m;
for(int i=l; i<=r; i++) {
if(i-l+1 >= m) {
sum+= (pref[i]-pref[i-m]);
}
}
cout << sum << endl;
}
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:40:9: warning: unused variable 'ujung' [-Wunused-variable]
40 | int ujung, kal;
| ^~~~~
Main.cpp:40:16: warning: unused variable 'kal' [-Wunused-variable]
40 | int ujung, kal;
| ^~~
Main.cpp:41:15: warning: unused variable 'sem' [-Wunused-variable]
41 | long long sem;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |