#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 25e4 + 7;
struct Query{
int t, l, r, c;
ll k;
};
struct BIT{
ll d[N];
void update(int x, int val){
for(; x < N; x += x & -x)
d[x] += val;
}
ll get(int x){
ll res = 0;
for(; x > 0; x -= x & -x)
res += d[x];
return res;
}
void updateRange(int l, int r, int val){
update(l, val);
update(r + 1, -val);
}
} bit;
struct SegTree{
int n;
ll d[N * 4], lazyVal[N * 4], lazyMax[N * 4];
void init(int _n){
n = _n;
}
void doLazy(int id, int l, int r){
d[id] += lazyVal[id];
d[id] = max(d[id], lazyMax[id]);
if (l < r){
lazyVal[id << 1] += lazyVal[id];
lazyMax[id << 1] += lazyVal[id];
lazyMax[id << 1] = max(lazyMax[id << 1], lazyMax[id]);
lazyVal[id << 1 | 1] += lazyVal[id];
lazyMax[id << 1 | 1] += lazyVal[id];
lazyMax[id << 1 | 1] = max(lazyMax[id << 1 | 1], lazyMax[id]);
}
lazyVal[id] = lazyMax[id] = 0;
}
void update(int id, int l, int r, int u, int v, int val){
doLazy(id, l, r);
if (v < l || r < u)
return;
if (u <= l && r <= v){
lazyVal[id] += val;
doLazy(id, l, r);
return;
}
int mid = (l + r) >> 1;
update(id << 1, l, mid, u, v, val);
update(id << 1 | 1, mid + 1, r, u, v, val);
}
ll get(int id, int l, int r, int pos){
doLazy(id, l, r);
if (pos < l || r < pos)
return 0;
if (l == r)
return d[id];
int mid = (l + r) >> 1;
return max(get(id << 1, l, mid, pos), get(id << 1 | 1, mid + 1, r, pos));
}
void update(int l, int r, int k){
update(1, 1, n, l, r, k);
}
ll get(int pos){
return get(1, 1, n, pos);
}
} st;
int n, m, q;
Query queries[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for(int i = 1; i <= q; i++){
cin >> queries[i].t;
if (queries[i].t == 1)
cin >> queries[i].l >> queries[i].r >> queries[i].c >> queries[i].k;
else if (queries[i].t == 2)
cin >> queries[i].l >> queries[i].r >> queries[i].k;
else
cin >> queries[i].l >> queries[i].k;
}
st.init(n);
for(int i = 1; i <= q; i++)
if (queries[i].t == 1) {
st.update(queries[i].l, queries[i].r, queries[i].k);
bit.updateRange(queries[i].l, queries[i].r, queries[i].k);
} else if (queries[i].t == 2) {
st.update(queries[i].l, queries[i].r, -queries[i].k);
} else {
if (st.get(queries[i].l) < queries[i].k){
cout << 0 << '\n';
} else {
ll x = bit.get(queries[i].l) - (st.get(queries[i].l) - queries[i].k);
for(int j = 1; j <= q; j++)
if (queries[j].t == 1 && queries[j].l <= queries[i].l && queries[i].l <= queries[j].r){
x -= queries[j].k;
if (x <= 0){
cout << queries[j].c << '\n';
break;
}
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
4 ms |
484 KB |
Output is correct |
22 |
Correct |
4 ms |
588 KB |
Output is correct |
23 |
Correct |
4 ms |
592 KB |
Output is correct |
24 |
Correct |
4 ms |
524 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
4 ms |
588 KB |
Output is correct |
28 |
Correct |
4 ms |
584 KB |
Output is correct |
29 |
Correct |
4 ms |
588 KB |
Output is correct |
30 |
Correct |
4 ms |
592 KB |
Output is correct |
31 |
Correct |
4 ms |
588 KB |
Output is correct |
32 |
Correct |
4 ms |
588 KB |
Output is correct |
33 |
Correct |
2 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
464 KB |
Output is correct |
35 |
Correct |
3 ms |
460 KB |
Output is correct |
36 |
Correct |
3 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
460 KB |
Output is correct |
38 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
6656 KB |
Output is correct |
2 |
Correct |
86 ms |
6720 KB |
Output is correct |
3 |
Correct |
73 ms |
6636 KB |
Output is correct |
4 |
Correct |
73 ms |
6680 KB |
Output is correct |
5 |
Correct |
80 ms |
6636 KB |
Output is correct |
6 |
Correct |
72 ms |
6724 KB |
Output is correct |
7 |
Correct |
770 ms |
2740 KB |
Output is correct |
8 |
Correct |
953 ms |
2744 KB |
Output is correct |
9 |
Correct |
132 ms |
6724 KB |
Output is correct |
10 |
Correct |
73 ms |
6720 KB |
Output is correct |
11 |
Correct |
90 ms |
6680 KB |
Output is correct |
12 |
Correct |
69 ms |
6708 KB |
Output is correct |
13 |
Correct |
872 ms |
6380 KB |
Output is correct |
14 |
Execution timed out |
1058 ms |
6628 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
23404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
74 ms |
6656 KB |
Output is correct |
22 |
Correct |
86 ms |
6720 KB |
Output is correct |
23 |
Correct |
73 ms |
6636 KB |
Output is correct |
24 |
Correct |
73 ms |
6680 KB |
Output is correct |
25 |
Correct |
80 ms |
6636 KB |
Output is correct |
26 |
Correct |
72 ms |
6724 KB |
Output is correct |
27 |
Correct |
770 ms |
2740 KB |
Output is correct |
28 |
Correct |
953 ms |
2744 KB |
Output is correct |
29 |
Correct |
132 ms |
6724 KB |
Output is correct |
30 |
Correct |
73 ms |
6720 KB |
Output is correct |
31 |
Correct |
90 ms |
6680 KB |
Output is correct |
32 |
Correct |
69 ms |
6708 KB |
Output is correct |
33 |
Correct |
872 ms |
6380 KB |
Output is correct |
34 |
Execution timed out |
1058 ms |
6628 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
7044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
4 ms |
484 KB |
Output is correct |
22 |
Correct |
4 ms |
588 KB |
Output is correct |
23 |
Correct |
4 ms |
592 KB |
Output is correct |
24 |
Correct |
4 ms |
524 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
4 ms |
588 KB |
Output is correct |
28 |
Correct |
4 ms |
584 KB |
Output is correct |
29 |
Correct |
4 ms |
588 KB |
Output is correct |
30 |
Correct |
4 ms |
592 KB |
Output is correct |
31 |
Correct |
4 ms |
588 KB |
Output is correct |
32 |
Correct |
4 ms |
588 KB |
Output is correct |
33 |
Correct |
2 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
464 KB |
Output is correct |
35 |
Correct |
3 ms |
460 KB |
Output is correct |
36 |
Correct |
3 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
460 KB |
Output is correct |
38 |
Correct |
3 ms |
460 KB |
Output is correct |
39 |
Correct |
74 ms |
6656 KB |
Output is correct |
40 |
Correct |
86 ms |
6720 KB |
Output is correct |
41 |
Correct |
73 ms |
6636 KB |
Output is correct |
42 |
Correct |
73 ms |
6680 KB |
Output is correct |
43 |
Correct |
80 ms |
6636 KB |
Output is correct |
44 |
Correct |
72 ms |
6724 KB |
Output is correct |
45 |
Correct |
770 ms |
2740 KB |
Output is correct |
46 |
Correct |
953 ms |
2744 KB |
Output is correct |
47 |
Correct |
132 ms |
6724 KB |
Output is correct |
48 |
Correct |
73 ms |
6720 KB |
Output is correct |
49 |
Correct |
90 ms |
6680 KB |
Output is correct |
50 |
Correct |
69 ms |
6708 KB |
Output is correct |
51 |
Correct |
872 ms |
6380 KB |
Output is correct |
52 |
Execution timed out |
1058 ms |
6628 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
4 ms |
484 KB |
Output is correct |
22 |
Correct |
4 ms |
588 KB |
Output is correct |
23 |
Correct |
4 ms |
592 KB |
Output is correct |
24 |
Correct |
4 ms |
524 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
4 ms |
588 KB |
Output is correct |
28 |
Correct |
4 ms |
584 KB |
Output is correct |
29 |
Correct |
4 ms |
588 KB |
Output is correct |
30 |
Correct |
4 ms |
592 KB |
Output is correct |
31 |
Correct |
4 ms |
588 KB |
Output is correct |
32 |
Correct |
4 ms |
588 KB |
Output is correct |
33 |
Correct |
2 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
464 KB |
Output is correct |
35 |
Correct |
3 ms |
460 KB |
Output is correct |
36 |
Correct |
3 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
460 KB |
Output is correct |
38 |
Correct |
3 ms |
460 KB |
Output is correct |
39 |
Correct |
74 ms |
6656 KB |
Output is correct |
40 |
Correct |
86 ms |
6720 KB |
Output is correct |
41 |
Correct |
73 ms |
6636 KB |
Output is correct |
42 |
Correct |
73 ms |
6680 KB |
Output is correct |
43 |
Correct |
80 ms |
6636 KB |
Output is correct |
44 |
Correct |
72 ms |
6724 KB |
Output is correct |
45 |
Correct |
770 ms |
2740 KB |
Output is correct |
46 |
Correct |
953 ms |
2744 KB |
Output is correct |
47 |
Correct |
132 ms |
6724 KB |
Output is correct |
48 |
Correct |
73 ms |
6720 KB |
Output is correct |
49 |
Correct |
90 ms |
6680 KB |
Output is correct |
50 |
Correct |
69 ms |
6708 KB |
Output is correct |
51 |
Correct |
872 ms |
6380 KB |
Output is correct |
52 |
Execution timed out |
1058 ms |
6628 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |