#include "bits/stdc++.h"
#define int long long
using namespace std;
const int sz = 1e5 + 5;
const int sm = 11;
int pf[sz], sf[sz];
int pj[sz], sj[sz];
int a[sz], b[sm];
int an, k;
void solve() {
int t;
cin >> t;
if (1 == t) {
for (int i = 0; i < k; i ++)
cin >> b[i];
for (int i = 0; i < k - 1; i ++) {
int tx = (i + k - 1) % k;
swap(a[b[i]], a[b[tx]]);
}
return;
}
int l, r, m;
cin >> l >> r >> m;
int n = r - l + 1;
int mxv = n - m + 1;
int le = l + mxv - 2;
int rs = r - mxv + 2;
int pjl = pj[le] - pj[l - 1];
int pfl = pf[le] - pf[l - 1];
int fpl = pjl - pfl * (l - 1);
int sjr = sj[rs] - sj[r + 1];
int sfr = sf[rs] - sf[r + 1];
int fsr = sjr - sfr * (an - r);
int rsms = l + mxv - 1;
int rsme = r - mxv + 1;
int rsm = pf[rsme] - pf[rsms - 1];
int tsm = fpl + fsr + rsm * mxv;
cout << tsm << '\n';
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, k;
cin >> n >> k;
an = n;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = 1; i <= n; i ++) {
pf[i] = pf[i - 1] + a[i];
pj[i] = pj[i - 1] + i * a[i];
}
for (int i = 1; i <= n; i ++) {
int rx = n - i + 1;
sf[rx] = sf[rx + 1] + a[rx];
sj[rx] = sj[rx + 1] + i * a[rx];
}
int q;
cin >> q;
while (q --)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
4004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |