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;
void solve() {
int n, k;
cin >> n >> k;
vector <int> a(n+3);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
if (x == 1) {
int ar[k+1];
for (int i = 1; i <= k; i++) {
cin >> ar[i];
}
vector <int> ns(k+3);
int f = a[ar[1]];
for (int i = 1; i < k; i++) {
a[ar[i]] = a[ar[i+1]];
}
a[ar[k]] = f;
// for (int i = 1; i <= n; i++) {
// cout << a[i] << " ";
// }
}
if (x == 2) {
int l, r, m;
cin >> l >> r >> m;
int sum = 0, main = 0;
// cout << "i: ";
for (int i = l; i < l + m; i++) {
sum += a[i];
// cout << a[i] << " ";
}
// cout << "\n" << "sum: " << sum << " ";
main += sum;
for (int i = l + m; i <= r; i++) {
sum -= a[i-m];
sum += a[i];
// cout << sum << " ";
main += sum;
}
cout << main << "\n";
}
}
}
/*
8 3
7 2 5 1 9 3 4 6
3
2 2 7 4
1 2 5 8
2 2 7 3
*/
signed main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |