# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
838495 |
2023-08-27T09:36:30 Z |
BlockOG |
Addk (eJOI21_addk) |
C++14 |
|
2000 ms |
1396 KB |
#include <iostream>
using namespace std;
int a[100000];
long long b[100001];
long long bsum(int n, int i) {
long long res = 0;
i = min(++i, n); while (i > 0) {
res += b[i];
i -= i & -i;
}
return res;
}
void bchg(int n, int i, int c) {
i++; while (i <= n) {
b[i] += c;
i += i & -i;
}
}
int main() {
int n, k; cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
bchg(n, i, a[i]);
}
int q; cin >> q;
for (int it = 0; it < q; it++) {
int code; cin >> code;
if (code == 1) {
if (k > 1) {
int i, j; cin >> i; i--; j = i;
int tmp = a[j];
for (int l = 1; l < k; l++) {
int m; cin >> m; m--;
bchg(n, i, a[m] - a[i]);
a[i] = a[m];
i = m;
}
bchg(n, i, tmp - a[i]);
a[i] = tmp;
} else cin >> code;
} else {
int l, r, m; cin >> l >> r >> m;
long long res = 0;
for (int i = l - 2; i < r - m; i++) res += bsum(n, i + m) - bsum(n, i);
cout << res << endl;
}
}
}
Compilation message
Main.cpp: In function 'long long int bsum(int, int)':
Main.cpp:10:7: warning: operation on 'i' may be undefined [-Wsequence-point]
10 | i = min(++i, n); while (i > 0) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
432 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
22 ms |
340 KB |
Output is correct |
4 |
Correct |
47 ms |
428 KB |
Output is correct |
5 |
Correct |
78 ms |
460 KB |
Output is correct |
6 |
Correct |
130 ms |
616 KB |
Output is correct |
7 |
Correct |
176 ms |
468 KB |
Output is correct |
8 |
Correct |
240 ms |
592 KB |
Output is correct |
9 |
Correct |
489 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1845 ms |
1028 KB |
Output is correct |
2 |
Execution timed out |
2025 ms |
872 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2033 ms |
1396 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |