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 <iostream>
using namespace std;
int a[100000];
long long b[100001];
long long bsum(int i) {
long long res = 0;
i++; while (i > 0) {
res += b[i];
i -= i & -i;
}
return res;
}
void bchg(int n, int i, int c) {
i++; while (i <= n) {
b[i] += c;
i += i & -i;
}
}
int main() {
int n, k; cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
bchg(n, i, a[i]);
}
int q; cin >> q;
for (int it = 0; it < q; it++) {
int code; cin >> code;
if (code == 1) {
if (k > 1) {
int i, j; cin >> i; i--; j = i;
int tmp = a[j];
for (int l = 1; l < k; l++) {
int m; cin >> m; m--;
bchg(n, i, a[m] - a[i]);
a[i] = a[m];
i = m;
}
bchg(n, i, tmp - a[i]);
a[i] = tmp;
} else cin >> code;
} else {
int l, r, m; cin >> l >> r >> m; r--, l--;
if (m > (r - l + 1) / 2) m = r - l + 2 - m;
long long res = 0;
for (int i = 0; i < m - 1; i++) {
res += (a[l + i] + a[r - i]) * (i + 1);
}
cout << res + (bsum(r + 1 - m) - bsum(l + m - 2)) * m << endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |