#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e6 + 1;
const int mod = 1e9 + 7;
template <typename T>
bool umx(T& a, T b) {
return (a < b ? a = b, 1 : 0);
}
template <typename T>
bool umn(T& a, T b) {
return (a > b ? a = b, 1 : 0);
}
void solve () {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i) cin >> a[i];
int q;
cin >> q;
while (q--) {
int type;
cin >> type;
if (type == 2) {
int l, r, x;
cin >> l >> r >> x;
ll ans = 0;
vector<ll> pref (n + 1);
for (int i = l; i <= r; ++i) pref[i] = pref[i - 1] + a[i];
for (int i = l; i <= r; ++i) {
if (i <= r - x + 1) ans += pref[i + x - 1] - pref[i - 1];
// int cnt = x;
// if (i <= r - x + 1) cnt = min (x, i - l + 1);
// else cnt = min (x, (r - x + 1) - (i - x + 1) + 1);
// ans += 1LL * a[i] * cnt;
}
cout << ans << "\n";
}
else {
vector<int> ve(k);
for (int i = 0; i < k; ++i) cin >> ve[i];
int last = a[ve[0]];
for (int i = 0; i < k - 1; ++i) a[ve[i]] = a[ve[i + 1]];
a[ve.back()] = last;
}
}
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
// freopen ("input.txt", "r", stdin);
// freopen ("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
while (T--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
10 ms |
348 KB |
Output is correct |
4 |
Correct |
24 ms |
560 KB |
Output is correct |
5 |
Correct |
39 ms |
604 KB |
Output is correct |
6 |
Correct |
65 ms |
656 KB |
Output is correct |
7 |
Correct |
87 ms |
692 KB |
Output is correct |
8 |
Correct |
123 ms |
708 KB |
Output is correct |
9 |
Correct |
241 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
959 ms |
1212 KB |
Output is correct |
2 |
Execution timed out |
2048 ms |
1820 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2051 ms |
1396 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |