// Try to be as positive as natural numbers :)
#include "bits/stdc++.h"
#define int long long
const int N = 1e5 + 5;
int a[N];
int p1[N], p2[N], s[N];
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, k;
std::cin >> n >> k;
for (int i = 1; i <= n; ++i) {
std::cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
p1[i] = p1[i - 1] + a[i] * i;
}
for (int i = 1; i <= n; ++i) {
p2[i] = p2[i - 1] + a[i];
}
for (int i = n; i >= 1; --i) {
s[i] = s[i + 1] + a[i] * (n - i + 1);
}
int q;
std::cin >> q;
while (q--) {
int t;
std::cin >> t;
if (t == 1) {
int i;
std::cin >> i;
continue;
}
int l, r, m;
std::cin >> l >> r >> m;
m = std::min(m, (r - l + 1) - m + 1);
int pt1 = p1[l + m - 2] - p1[l - 1] - (l - 1) * (p2[l + m - 2] - p2[l - 1]);
int pt2 = s[r - m + 2] - s[r + 1] - (n - r) * (p2[r] - p2[r - m + 1]);
int pt3 = (p2[r - m + 1] - p2[l + m - 2]) * m;
int ans = pt1 + pt2 + pt3;
std::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... |