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>
#include <vector>
using namespace std;
using ll = long long int;
const int N = 100002;
ll n, K;
int a[N];
int main() {
cin >> n >> K;
for (int i = 1; i <= n; ++i)
cin >> a[i];
int q; cin >> q;
for (int tc = 1; tc <= q; ++tc) {
int op; cin >> op;
if (op == 1) {
int x, prev, val; cin >> x;
prev = x, val = a[x];
for (int i = 2; i < K; ++i) {
cin >> x;
a[prev] = a[x];
prev = x;
}
cin >> x;
a[prev] = a[x];
a[x] = val;
}
else {
int l, r, m;
cin >> l >> r >> m;
ll sum = 0, ans = 0;
for (int i = l; i < l + m; ++i)
sum += a[i];
ans += sum;
//cout << sum << '\n';
int tl = l, tr = l + m - 1;
while (tr < r) {
sum -= a[tl++];
sum += a[++tr];
ans += sum;
//cout << sum << '\n';
}
cout << ans << '\n';
}
}
return 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... |