#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double db;
#define int ll
#define all(x) (x).begin(), (x).end()
#define md ((tl + tr) >> 1)
#define TL v + v, tl, md
#define TR v + v + 1, md + 1, tr
constexpr int maxn = 300'003;
constexpr ll inf = 1e18 + 7;
constexpr ll M = 998244353;
int binpow(int a, int n) {
if (n == 0)
return 1;
if (n & 1)
return a * binpow(a, n - 1) % M;
int x = binpow(a, n >> 1);
return x * x % M;
}
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const db eps = 0.000000000000001;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
int n, k, a[maxn], q, ps[maxn], pss[maxn], id[maxn], b[maxn];
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ps[i] = ps[i - 1] + a[i];
pss[i] = pss[i - 1] + ps[i];
}
cin >> q;
while (q--) {
int tp, l, r, m;
cin >> tp;
if (tp == 1) {
for (int i = 0; i < k; i++)
cin >> id[i];
for (int i = 0; i < k; i++)
b[i] = a[id[i]];
for (int i = 0; i < k; i++)
a[id[i]] = b[(i + 1) % k];
} else {
cin >> l >> r >> m;
cout << pss[r] - pss[l + m - 2] - (pss[r - m] - pss[l - 2]) << '\n';
}
}
}
signed main() {
// freopen("qi.in", "r", stdin);
// freopen("qi.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
// cin >> test;
while (test--) {
solve();
cout << '\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... |