# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
622465 |
2022-08-04T09:59:07 Z |
pakapu |
Addk (eJOI21_addk) |
C++14 |
|
1325 ms |
7564 KB |
#pragma GCC optimize ("O3")
#include <iostream>
#include <vector>
using namespace std;
long long tree[131072 * 2 - 1];
int sz = 131072;
void init(int n) {
sz = 1 << (32 - __builtin_clz(n - 1));
}
void set(int pos, int val, int x, int lx, int rx) {
if(rx - lx == 1) {
tree[x] = val;
return;
}
int mid = (lx + rx) / 2;
if(pos >= mid) {
set(pos, val, x * 2 + 2, mid, rx);
}
else {
set(pos, val, x * 2 + 1, lx, mid);
}
tree[x] = tree[x * 2 + 1] + tree[x * 2 + 2];
}
void set(int pos, int val) {
set(pos, val, 0, 0, sz);
}
long long get(int l, int r, int x, int lx, int rx) {
if(rx <= l || lx >= r) {
return 0;
}
if(lx >= l && rx <= r) {
return (long long)tree[x];
}
int mid = (lx + rx) / 2;
return get(l, r, x * 2 + 1, lx, mid) + get(l, r, x * 2 + 2, mid, rx);
}
long long get(int l, int r) {
return get(l, r + 1, 0, 0, sz);
}
long long get_element(int x) {
return tree[sz - 1 + x];
}
void rebuild(int x, int lx, int rx) {
if(rx - lx == 2) {
tree[x] = tree[x * 2 + 1] + tree[x * 2 + 2];
return;
}
int mid = (lx + rx) / 2;
rebuild(x * 2 + 1, lx, mid);
rebuild(x * 2 + 2, mid, rx);
tree[x] = tree[x * 2 + 1] + tree[x * 2 + 2];
}
void rebuild() {
rebuild(0, 0, sz);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
init(n);
for(int i = 0; i < n; i++) {
long long tmp;
cin >> tmp;
set(i, tmp);
}
for(int i = n; i < sz; i++) {
set(i, 0);
}
int q;
cin >> q;
while(q--) {
int x;
cin >> x;
if(x == 1) {
vector<int> a(k);
vector<int> tmp(k);
for(int i = 0; i < k; i++) {
cin >> a[i];
a[i]--;
//tmp[i] = sg.get(a[i], a[i]);
tmp[i] = get_element(a[i]);
}
for(int i = 0; i < k; i++) {
set(a[((i - 1) % k + k) % k], tmp[i]);
}
}
else if(x == 2) {
int l, r, m;
cin >> l >> r >> m;
l--;
r--;
long long s = 0;
long long sprev = get(l, r);
for(int i = 0; i < min(r - l + 1 - m + 1, m) && r - l + 1 - 2 * i > 0; i++) {
s += sprev;
sprev = sprev - get_element(l + i) - get_element(r - i);
}
cout << s << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
9 ms |
600 KB |
Output is correct |
7 |
Correct |
9 ms |
596 KB |
Output is correct |
8 |
Correct |
11 ms |
600 KB |
Output is correct |
9 |
Correct |
21 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
1640 KB |
Output is correct |
2 |
Correct |
137 ms |
1876 KB |
Output is correct |
3 |
Correct |
277 ms |
2872 KB |
Output is correct |
4 |
Correct |
835 ms |
5160 KB |
Output is correct |
5 |
Correct |
1325 ms |
6396 KB |
Output is correct |
6 |
Correct |
1186 ms |
6052 KB |
Output is correct |
7 |
Correct |
974 ms |
6016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
218 ms |
3648 KB |
Output is correct |
2 |
Correct |
816 ms |
6000 KB |
Output is correct |
3 |
Correct |
208 ms |
7564 KB |
Output is correct |
4 |
Correct |
1227 ms |
6616 KB |
Output is correct |