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>
typedef long long ll;
using namespace std;
const int nx = 1e5 + 5;
int n, k;
ll a[nx];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i=1; i<=n; i++){
cin>>a[i];
a[i] += a[i-1];
}
int q, type, dummy;
cin>>q;
while(q--){
cin >> type;
if(type == 1){
for(int i=1; i<=k; i++) cin >> dummy;
}
else{
ll ret = 0;
int l, r, m;
cin >> l >> r >> m;
int top = min(m, r-l+1-m+1);
for(int i=1; i<=top; i++){
ret += (a[r] - a[l-1]);
--r;
++l;
}
cout << ret <<'\n';
}
}
return 0;
}
/*
if k = 1;
query 1 doesn't change anything
focus on query type 2 only:
notice it only take prefix sum
7 2 5 1 9 3 4 6
^ ^ ^ ^
^ ^
^ ^
2 2 7 4
top = min(m-1, r-l+1-m+1)
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |