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;
const int maxn = 1e5;
int n, k, q, a[maxn+5], pref[maxn+5], pos[15], pre[maxn+5], suf[maxn+5];
signed 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];
}
pref[0] = pre[0] = suf[n+1] = 0;
for (int i=1; i<=n; i++) {
pref[i] = pref[i-1] + a[i];
pre[i] = pre[i-1] + a[i] * i;
suf[n-i+1] = suf[n-i+2] + a[n-i+1] * i;
}
cin >> q;
while (q--) {
int t;
cin >> t;
if (t == 1) {
for (int i=1; i<=k; i++) {
cin >> pos[i];
}
continue; // subtask 1, 2
}
else {
int l, r, m;
cin >> l >> r >> m;
int len = r - l + 1;
int h = min(len/2, m);
int x = l + h - 1, y = r - h + 1;
int ans = (h*(pref[y] - pref[x-1])) + (pre[x-1]-pre[l-1]-(l-1)*(pref[x-1]-pref[l-1])) + (suf[y+1]-suf[r+1]-(n-r)*(pref[r]-pref[y]));
// cout << "len: " << len << " x: " << x << " y: " << y << " h: " << h << "\n";
cout << ans << "\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |