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>
#define int long long
using namespace std;
int32_t main () {
int n, k;
cin >> n >> k;
int arr[n+1], prefix1[n+1] = {0}, prefix2[n+1] = {0};
for(int i = 1;i<=n;i++) {
cin >> arr[i];
prefix1[i] = prefix1[i-1] + arr[i];
prefix2[i] = prefix2[i-1] + arr[i]*i;
}
int q;
cin >> q;
while(q--) {
int k;
cin >> k;
if(k == 1) {
int d;
cin >> d;
}
else {
int ans = 0;
int l, r, m;
cin >> l >> r >> m;
m = min(r-l-m + 2, m);
int a = (prefix2[l+m-1] - prefix2[l-1])-(prefix1[l+m-1] - prefix1[l-1])*(l-1);
int b = (prefix1[r-m] - prefix1[l+m-1])*m;
int c = (prefix1[r] - prefix1[r-m])*(r+1) - (prefix2[r] - prefix2[r-m]);
cout<<a+b+c<<endl;
}
}
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:23:8: warning: unused variable 'ans' [-Wunused-variable]
23 | int ans = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |