#include <iostream>
#include "bits/stdc++.h"
#define forR(i, x) for(int i=0; i < (x); ++i)
#define REP(i, a, b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(), x.end()
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define asst(x) if(!(x)) exit(1)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MN = 3e5 + 10;
int len[MN];
struct ev{
int ti;
ll to;
};
ll ch[MN];
int c[MN];
bool us[MN];
vector<ev> evs[MN];
struct query{
int ai, i; ll b;
};
vector<query> qus[MN];
int ans[MN];
struct node {
ll ps, psm;
ll nSum;
};
node seg[4 * MN];
node comb(node a, node b) {
return {a.ps + b.ps, min(a.psm, a.ps + b.psm), a.nSum + b.nSum};
}
void upd(int v, int nl, int nr, int i, ll to) {
if(nl == i && nr == i) seg[v] = {to, min(0LL, to), to < 0 ? to : 0};
else {
int mid = (nl+nr)/2;
if(i <= mid) upd(2*v, nl, mid, i, to);
else upd(2*v+1, mid+1, nr, i, to);
seg[v] = comb(seg[2*v], seg[2*v+1]);
}
}
node qu(int v, int nl, int nr, int l, int r) {
if(l > r) return {0, 0, 0};
if(nl == l && nr == r) return seg[v];
int mid = (nl+nr)/2;
return comb(qu(2*v, nl, mid, l, min(mid, r)),
qu(2*v+1, mid+1, nr, max(mid+1, l), r));
}
int main(){
boost();
int n, m, q; cin >> n >> m >> q;
int ai=0;
forR(i, q){
int ty; cin >> ty;
if(ty == 1){
int l, r, k; cin >> l >> r >> c[i] >> k;
evs[l].push_back({i, k});
evs[r+1].push_back({i, 0});
} else if(ty == 2){
int l, r, k; cin >> l >> r >> k;
evs[l].push_back({i, -k});
evs[r+1].push_back({i, 0});
} else {
int a; ll b; cin >> a >> b;
qus[a].push_back({ai++, i, b});
}
}
REP(i, 1, n+1){
for(auto [ti, to] : evs[i]) {
ch[ti] = to;
upd(1, 0, q-1, ti, to);
}
for(auto [ai, ti, b] : qus[i]) {
int j = 0;
bool found = false;
ll cur = 0;
for(; j <= ti && !found;) {
cur = max(0LL, cur + ch[j]);
node upTo = qu(1, 0, q-1, 0, j);
if(upTo.ps - upTo.psm + qu(1, 0, q-1, j+1, ti).nSum >= b) {
found = true;
} else {
++j;
}
}
if(found) {
ans[ai] = c[j];
} else ans[ai] = 0;
}
}
forR(i, ai) cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
14680 KB |
Output is correct |
2 |
Correct |
178 ms |
14680 KB |
Output is correct |
3 |
Correct |
55 ms |
14684 KB |
Output is correct |
4 |
Correct |
106 ms |
14680 KB |
Output is correct |
5 |
Correct |
133 ms |
14688 KB |
Output is correct |
6 |
Correct |
117 ms |
14680 KB |
Output is correct |
7 |
Correct |
89 ms |
14680 KB |
Output is correct |
8 |
Correct |
128 ms |
14776 KB |
Output is correct |
9 |
Correct |
123 ms |
14680 KB |
Output is correct |
10 |
Correct |
114 ms |
14680 KB |
Output is correct |
11 |
Correct |
126 ms |
14684 KB |
Output is correct |
12 |
Correct |
146 ms |
14936 KB |
Output is correct |
13 |
Correct |
110 ms |
14680 KB |
Output is correct |
14 |
Correct |
166 ms |
14684 KB |
Output is correct |
15 |
Correct |
78 ms |
14680 KB |
Output is correct |
16 |
Correct |
169 ms |
14684 KB |
Output is correct |
17 |
Correct |
72 ms |
14680 KB |
Output is correct |
18 |
Correct |
119 ms |
14680 KB |
Output is correct |
19 |
Correct |
63 ms |
14768 KB |
Output is correct |
20 |
Correct |
91 ms |
14776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
14680 KB |
Output is correct |
2 |
Correct |
178 ms |
14680 KB |
Output is correct |
3 |
Correct |
55 ms |
14684 KB |
Output is correct |
4 |
Correct |
106 ms |
14680 KB |
Output is correct |
5 |
Correct |
133 ms |
14688 KB |
Output is correct |
6 |
Correct |
117 ms |
14680 KB |
Output is correct |
7 |
Correct |
89 ms |
14680 KB |
Output is correct |
8 |
Correct |
128 ms |
14776 KB |
Output is correct |
9 |
Correct |
123 ms |
14680 KB |
Output is correct |
10 |
Correct |
114 ms |
14680 KB |
Output is correct |
11 |
Correct |
126 ms |
14684 KB |
Output is correct |
12 |
Correct |
146 ms |
14936 KB |
Output is correct |
13 |
Correct |
110 ms |
14680 KB |
Output is correct |
14 |
Correct |
166 ms |
14684 KB |
Output is correct |
15 |
Correct |
78 ms |
14680 KB |
Output is correct |
16 |
Correct |
169 ms |
14684 KB |
Output is correct |
17 |
Correct |
72 ms |
14680 KB |
Output is correct |
18 |
Correct |
119 ms |
14680 KB |
Output is correct |
19 |
Correct |
63 ms |
14768 KB |
Output is correct |
20 |
Correct |
91 ms |
14776 KB |
Output is correct |
21 |
Correct |
177 ms |
14684 KB |
Output is correct |
22 |
Correct |
161 ms |
14680 KB |
Output is correct |
23 |
Correct |
93 ms |
14772 KB |
Output is correct |
24 |
Correct |
111 ms |
14776 KB |
Output is correct |
25 |
Correct |
90 ms |
14792 KB |
Output is correct |
26 |
Correct |
110 ms |
14780 KB |
Output is correct |
27 |
Correct |
112 ms |
14772 KB |
Output is correct |
28 |
Correct |
98 ms |
14680 KB |
Output is correct |
29 |
Correct |
128 ms |
14680 KB |
Output is correct |
30 |
Correct |
115 ms |
14740 KB |
Output is correct |
31 |
Correct |
123 ms |
14680 KB |
Output is correct |
32 |
Correct |
131 ms |
14800 KB |
Output is correct |
33 |
Correct |
127 ms |
14684 KB |
Output is correct |
34 |
Correct |
179 ms |
14796 KB |
Output is correct |
35 |
Correct |
130 ms |
14680 KB |
Output is correct |
36 |
Correct |
157 ms |
14692 KB |
Output is correct |
37 |
Correct |
41 ms |
14680 KB |
Output is correct |
38 |
Correct |
81 ms |
14796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
20328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1048 ms |
27772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
14680 KB |
Output is correct |
2 |
Correct |
178 ms |
14680 KB |
Output is correct |
3 |
Correct |
55 ms |
14684 KB |
Output is correct |
4 |
Correct |
106 ms |
14680 KB |
Output is correct |
5 |
Correct |
133 ms |
14688 KB |
Output is correct |
6 |
Correct |
117 ms |
14680 KB |
Output is correct |
7 |
Correct |
89 ms |
14680 KB |
Output is correct |
8 |
Correct |
128 ms |
14776 KB |
Output is correct |
9 |
Correct |
123 ms |
14680 KB |
Output is correct |
10 |
Correct |
114 ms |
14680 KB |
Output is correct |
11 |
Correct |
126 ms |
14684 KB |
Output is correct |
12 |
Correct |
146 ms |
14936 KB |
Output is correct |
13 |
Correct |
110 ms |
14680 KB |
Output is correct |
14 |
Correct |
166 ms |
14684 KB |
Output is correct |
15 |
Correct |
78 ms |
14680 KB |
Output is correct |
16 |
Correct |
169 ms |
14684 KB |
Output is correct |
17 |
Correct |
72 ms |
14680 KB |
Output is correct |
18 |
Correct |
119 ms |
14680 KB |
Output is correct |
19 |
Correct |
63 ms |
14768 KB |
Output is correct |
20 |
Correct |
91 ms |
14776 KB |
Output is correct |
21 |
Execution timed out |
1047 ms |
20328 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1045 ms |
19664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
14680 KB |
Output is correct |
2 |
Correct |
178 ms |
14680 KB |
Output is correct |
3 |
Correct |
55 ms |
14684 KB |
Output is correct |
4 |
Correct |
106 ms |
14680 KB |
Output is correct |
5 |
Correct |
133 ms |
14688 KB |
Output is correct |
6 |
Correct |
117 ms |
14680 KB |
Output is correct |
7 |
Correct |
89 ms |
14680 KB |
Output is correct |
8 |
Correct |
128 ms |
14776 KB |
Output is correct |
9 |
Correct |
123 ms |
14680 KB |
Output is correct |
10 |
Correct |
114 ms |
14680 KB |
Output is correct |
11 |
Correct |
126 ms |
14684 KB |
Output is correct |
12 |
Correct |
146 ms |
14936 KB |
Output is correct |
13 |
Correct |
110 ms |
14680 KB |
Output is correct |
14 |
Correct |
166 ms |
14684 KB |
Output is correct |
15 |
Correct |
78 ms |
14680 KB |
Output is correct |
16 |
Correct |
169 ms |
14684 KB |
Output is correct |
17 |
Correct |
72 ms |
14680 KB |
Output is correct |
18 |
Correct |
119 ms |
14680 KB |
Output is correct |
19 |
Correct |
63 ms |
14768 KB |
Output is correct |
20 |
Correct |
91 ms |
14776 KB |
Output is correct |
21 |
Correct |
177 ms |
14684 KB |
Output is correct |
22 |
Correct |
161 ms |
14680 KB |
Output is correct |
23 |
Correct |
93 ms |
14772 KB |
Output is correct |
24 |
Correct |
111 ms |
14776 KB |
Output is correct |
25 |
Correct |
90 ms |
14792 KB |
Output is correct |
26 |
Correct |
110 ms |
14780 KB |
Output is correct |
27 |
Correct |
112 ms |
14772 KB |
Output is correct |
28 |
Correct |
98 ms |
14680 KB |
Output is correct |
29 |
Correct |
128 ms |
14680 KB |
Output is correct |
30 |
Correct |
115 ms |
14740 KB |
Output is correct |
31 |
Correct |
123 ms |
14680 KB |
Output is correct |
32 |
Correct |
131 ms |
14800 KB |
Output is correct |
33 |
Correct |
127 ms |
14684 KB |
Output is correct |
34 |
Correct |
179 ms |
14796 KB |
Output is correct |
35 |
Correct |
130 ms |
14680 KB |
Output is correct |
36 |
Correct |
157 ms |
14692 KB |
Output is correct |
37 |
Correct |
41 ms |
14680 KB |
Output is correct |
38 |
Correct |
81 ms |
14796 KB |
Output is correct |
39 |
Execution timed out |
1047 ms |
20328 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
14680 KB |
Output is correct |
2 |
Correct |
178 ms |
14680 KB |
Output is correct |
3 |
Correct |
55 ms |
14684 KB |
Output is correct |
4 |
Correct |
106 ms |
14680 KB |
Output is correct |
5 |
Correct |
133 ms |
14688 KB |
Output is correct |
6 |
Correct |
117 ms |
14680 KB |
Output is correct |
7 |
Correct |
89 ms |
14680 KB |
Output is correct |
8 |
Correct |
128 ms |
14776 KB |
Output is correct |
9 |
Correct |
123 ms |
14680 KB |
Output is correct |
10 |
Correct |
114 ms |
14680 KB |
Output is correct |
11 |
Correct |
126 ms |
14684 KB |
Output is correct |
12 |
Correct |
146 ms |
14936 KB |
Output is correct |
13 |
Correct |
110 ms |
14680 KB |
Output is correct |
14 |
Correct |
166 ms |
14684 KB |
Output is correct |
15 |
Correct |
78 ms |
14680 KB |
Output is correct |
16 |
Correct |
169 ms |
14684 KB |
Output is correct |
17 |
Correct |
72 ms |
14680 KB |
Output is correct |
18 |
Correct |
119 ms |
14680 KB |
Output is correct |
19 |
Correct |
63 ms |
14768 KB |
Output is correct |
20 |
Correct |
91 ms |
14776 KB |
Output is correct |
21 |
Correct |
177 ms |
14684 KB |
Output is correct |
22 |
Correct |
161 ms |
14680 KB |
Output is correct |
23 |
Correct |
93 ms |
14772 KB |
Output is correct |
24 |
Correct |
111 ms |
14776 KB |
Output is correct |
25 |
Correct |
90 ms |
14792 KB |
Output is correct |
26 |
Correct |
110 ms |
14780 KB |
Output is correct |
27 |
Correct |
112 ms |
14772 KB |
Output is correct |
28 |
Correct |
98 ms |
14680 KB |
Output is correct |
29 |
Correct |
128 ms |
14680 KB |
Output is correct |
30 |
Correct |
115 ms |
14740 KB |
Output is correct |
31 |
Correct |
123 ms |
14680 KB |
Output is correct |
32 |
Correct |
131 ms |
14800 KB |
Output is correct |
33 |
Correct |
127 ms |
14684 KB |
Output is correct |
34 |
Correct |
179 ms |
14796 KB |
Output is correct |
35 |
Correct |
130 ms |
14680 KB |
Output is correct |
36 |
Correct |
157 ms |
14692 KB |
Output is correct |
37 |
Correct |
41 ms |
14680 KB |
Output is correct |
38 |
Correct |
81 ms |
14796 KB |
Output is correct |
39 |
Execution timed out |
1047 ms |
20328 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |