# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
632491 |
2022-08-20T07:46:26 Z |
pragmatist |
Addk (eJOI21_addk) |
C++17 |
|
2000 ms |
5092 KB |
#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define sz(v) (int)v.size()
#define pb push_back
#define x first
#define y second
#define int long long
using namespace std;
using pii = pair<int, int>;
const int N = (int)1e5 + 7;
int n, k, q, b[N], a[N];
ll p[N], z[N];
vector<int> c;
void build() {
for(int i = 1; i <= n; ++i) {
a[i] = b[i];
p[i] = p[i - 1] + a[i];
z[i] = z[i - 1] + p[i];
}
}
ll get(int l) {
ll ans = z[l];
for(auto i : c) {
if(i > l) continue;
int ch = l - i + 1;
ans -= 1ll * ch * a[i];
ans += 1ll * ch * b[i];
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
b[i] = a[i];
}
build();
cin >> q;
while(q--) {
char tp;
cin >> tp;
if(tp == '1') {
vector<int> v(k);
for(auto &x : v) cin >> x;
int o = b[v[0]];
for(int i = 0; i < k - 1; ++i) {
b[v[i]] = b[v[i + 1]];
c.pb(v[i]);
}
c.pb(v.back());
b[v.back()] = o;
// if(1ll * sz(c) * sz(c) >= n) {
// build();
// c.clear();
// }
} else {
int l, r, m;
cin >> l >> r >> m;
ll ans = get(r) - get(l + m - 2);
ans -= get(r - m) - (l - 2 < 0 ? 0 : get(l - 2));
cout << ans << nl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
368 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
520 KB |
Output is correct |
6 |
Correct |
7 ms |
468 KB |
Output is correct |
7 |
Correct |
10 ms |
628 KB |
Output is correct |
8 |
Correct |
13 ms |
652 KB |
Output is correct |
9 |
Correct |
25 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
1236 KB |
Output is correct |
2 |
Correct |
236 ms |
1720 KB |
Output is correct |
3 |
Correct |
408 ms |
2116 KB |
Output is correct |
4 |
Correct |
1200 ms |
3720 KB |
Output is correct |
5 |
Correct |
1869 ms |
5092 KB |
Output is correct |
6 |
Execution timed out |
2080 ms |
4480 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2089 ms |
2656 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |