// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
using ll = long long;
using T = array<ll, 2>;
struct Seg {
const ll ID = 0;
vector<ll> suf, pos, all; int N;
void init(int n) {
N = 1; while(N < n) N *= 2;
suf.assign(2*N, 0); pos.assign(2*N, 0); all.assign(2*N, 0);
}
void pull(int p) {
pos[p] = pos[2*p] + pos[2*p+1];
all[p] = all[2*p] + all[2*p+1];
suf[p] = max(suf[2*p] + all[2*p+1], suf[2*p+1]);
}
void upd(int p, ll v, int x, int L, int R) {
if (p < L || R < p) return;
if (L == R) {
suf[x] = all[x] = v;
pos[x] = max(v, 0LL);
return;
}
int M = (L+R)/2;
upd(p, v, 2*x, L, M); upd(p, v, 2*x+1, M+1, R);
pull(x);
}
T max_suf(int l, int r, int x, int L, int R) {
if (r < L || R < l) return {0, 0};
if (l <= L && R <= r) return {suf[x], all[x]};
int M = (L+R)/2;
T a = max_suf(l, r, 2*x, L, M), b = max_suf(l, r, 2*x+1, M+1, R);
return {max(a[0] + b[1], b[0]), a[1] + b[1]};
};
ll sum_pos(int l, int r, int x, int L, int R) {
if (r < L || R < l) return 0;
if (l <= L && R <= r) return pos[x];
int M = (L+R)/2;
return sum_pos(l, r, 2*x, L, M) + sum_pos(l, r, 2*x+1, M+1, R);
}
ll walk(int l, int r, ll v, ll V, int x, int L, int R) {
// cout << x << " " << L << " " << R << " " << V << endl;
// cout << l << " " << r << " " << v << endl;
if (r < L || R < l || v > V) return -1;
if (L == R) return L;
int M = (L+R)/2;
int res = walk(l, r, v, V - pos[2*x+1], 2*x, L, M);
if (res == -1) return walk(l, r, v, V, 2*x+1, M+1, R);
return res;
}
void upd(int p, int x) { upd(p, x, 1, 0, N-1); }
T max_suf(int l, int r) { return max_suf(l, r, 1, 0, N-1); }
ll sum_pos(int l, int r) { return sum_pos(l, r, 1, 0, N-1); }
ll walk(int l, int r, ll v) { return walk(l, r, v, pos[1], 1, 0, N-1); }
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M, Q; cin >> N >> M >> Q;
vector<vector<int>> QL(N), QR(N), QQ(N);
vector<int> C(Q), K(Q);
for(int q = 0; q < Q; q++) {
int t; cin >> t;
if (t == 1) {
int l, r; cin >> l >> r >> C[q] >> K[q]; --l, --r;
QL[l].push_back(q);
QR[r].push_back(q);
}
if (t == 2) {
int l, r; cin >> l >> r >> K[q]; --l, --r;
K[q] = -K[q], C[q] = -1;
QL[l].push_back(q);
QR[r].push_back(q);
}
if (t == 3) {
int i; cin >> i >> K[q]; --i;
QQ[i].push_back(q);
}
}
Seg st; st.init(Q);
vector<ll> ans(Q, -1);
for(int i = 0; i < N; i++) {
for(auto q : QL[i]) { st.upd(q, K[q]);/* cout << "ON: " << q << endl;*/ }
for(auto q : QQ[i]) {
ll pos = st.sum_pos(0, q), suf = st.max_suf(0, q)[0];
ll I = pos - suf + K[q];
// cout << "INFO: " << q << " " << pos << " " << suf << " " << I << endl;
int res = st.walk(0, q, I);
ans[q] = (res == -1 ? 0 : C[res]);
// cout << "DONE: " << res << endl;
}
for(auto q : QR[i]) { st.upd(q, 0); /*cout << "OFF: " << q << endl;*/ }
}
for(int q = 0; q < Q; q++) if (ans[q] != -1) cout << ans[q] << nl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
584 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
584 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Runtime error |
1 ms |
800 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
12716 KB |
Output is correct |
2 |
Correct |
74 ms |
12832 KB |
Output is correct |
3 |
Correct |
75 ms |
12744 KB |
Output is correct |
4 |
Correct |
64 ms |
12748 KB |
Output is correct |
5 |
Correct |
69 ms |
12824 KB |
Output is correct |
6 |
Correct |
69 ms |
12848 KB |
Output is correct |
7 |
Correct |
35 ms |
5736 KB |
Output is correct |
8 |
Correct |
44 ms |
5844 KB |
Output is correct |
9 |
Correct |
73 ms |
12740 KB |
Output is correct |
10 |
Correct |
65 ms |
12716 KB |
Output is correct |
11 |
Correct |
68 ms |
12744 KB |
Output is correct |
12 |
Correct |
75 ms |
12752 KB |
Output is correct |
13 |
Correct |
57 ms |
10492 KB |
Output is correct |
14 |
Correct |
72 ms |
12636 KB |
Output is correct |
15 |
Correct |
62 ms |
10936 KB |
Output is correct |
16 |
Correct |
73 ms |
12820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
43084 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
584 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Correct |
65 ms |
12716 KB |
Output is correct |
22 |
Correct |
74 ms |
12832 KB |
Output is correct |
23 |
Correct |
75 ms |
12744 KB |
Output is correct |
24 |
Correct |
64 ms |
12748 KB |
Output is correct |
25 |
Correct |
69 ms |
12824 KB |
Output is correct |
26 |
Correct |
69 ms |
12848 KB |
Output is correct |
27 |
Correct |
35 ms |
5736 KB |
Output is correct |
28 |
Correct |
44 ms |
5844 KB |
Output is correct |
29 |
Correct |
73 ms |
12740 KB |
Output is correct |
30 |
Correct |
65 ms |
12716 KB |
Output is correct |
31 |
Correct |
68 ms |
12744 KB |
Output is correct |
32 |
Correct |
75 ms |
12752 KB |
Output is correct |
33 |
Correct |
57 ms |
10492 KB |
Output is correct |
34 |
Correct |
72 ms |
12636 KB |
Output is correct |
35 |
Correct |
62 ms |
10936 KB |
Output is correct |
36 |
Correct |
73 ms |
12820 KB |
Output is correct |
37 |
Correct |
60 ms |
11556 KB |
Output is correct |
38 |
Correct |
56 ms |
11208 KB |
Output is correct |
39 |
Correct |
31 ms |
5292 KB |
Output is correct |
40 |
Correct |
36 ms |
5660 KB |
Output is correct |
41 |
Correct |
62 ms |
12332 KB |
Output is correct |
42 |
Correct |
64 ms |
12364 KB |
Output is correct |
43 |
Correct |
70 ms |
12292 KB |
Output is correct |
44 |
Correct |
70 ms |
12384 KB |
Output is correct |
45 |
Correct |
87 ms |
12388 KB |
Output is correct |
46 |
Correct |
64 ms |
12292 KB |
Output is correct |
47 |
Correct |
49 ms |
10832 KB |
Output is correct |
48 |
Correct |
59 ms |
11160 KB |
Output is correct |
49 |
Correct |
44 ms |
9704 KB |
Output is correct |
50 |
Correct |
55 ms |
11768 KB |
Output is correct |
51 |
Correct |
86 ms |
12424 KB |
Output is correct |
52 |
Correct |
67 ms |
12356 KB |
Output is correct |
53 |
Correct |
50 ms |
11136 KB |
Output is correct |
54 |
Correct |
65 ms |
12796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
12492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
584 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Runtime error |
1 ms |
800 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
584 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Runtime error |
1 ms |
800 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |