#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define dbg(x) cerr << #x << " " << x << "\n"
struct node_t {
ll sum_max;
ll sum;
};
class segtree {
public:
vector <node_t> seg;
int n;
segtree (int n) {
this->n = n;
seg.resize (1 + 4 * n);
}
node_t combine (node_t lnode, node_t rnode) {
return {
max (rnode.sum_max, rnode.sum + lnode.sum_max),
lnode.sum + rnode.sum
};
}
void update (int node, int lb, int rb, int pos, ll val) {
if (lb == rb) {
seg[node] = {max (0ll, val), val};
return;
}
int mid = (lb + rb) / 2, lnode = node * 2, rnode = node * 2 + 1;
if (pos <= mid)
update (lnode, lb, mid, pos, val);
else
update (rnode, mid + 1, rb, pos, val);
seg[node] = combine (seg[lnode], seg[rnode]);
}
node_t query (int node, int lb, int rb, int ql, int qr) {
if (ql <= lb && rb <= qr) {
return seg[node];
}
int mid = (lb + rb) / 2, lnode = node * 2, rnode = node * 2 + 1;
node_t ans = {0, 0};
if (ql <= mid)
ans = combine (ans, query (lnode, lb, mid, ql, qr));
if (qr > mid)
ans = combine (ans, query (rnode, mid + 1, rb, ql, qr));
return ans;
}
};
class fenwick {
public:
vector <ll> aib;
int n;
fenwick (int n) {
this->n = n;
aib.resize (1 + n);
}
void upd (int pos, ll val) {
while (pos <= n) {
aib[pos] += val;
pos += pos & -pos;
}
}
ll qry (int pos) {
ll ans = 0;
while (pos > 0) {
ans += aib[pos];
pos -= pos & -pos;
}
return ans;
}
ll qry (int l, int r) {
return qry (r) - qry (l - 1);
}
int kth (ll k) {
int ans = 0;
for (int step = (1 << 20); step > 0; step /= 2)
if (ans + step <= n && aib[ans + step] < k) {
ans += step;
k -= aib[ans];
}
return ans + 1;
}
};
const int MAX_N = 25e4;
vector <pair <ll, ll>> qry[1 + MAX_N], upd_seg[1 + MAX_N], upd_fen[1 + MAX_N]; /// first-> pos, second-> value
ll group[1 + MAX_N];
ll sol[1 + MAX_N];
int main () {
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= q; i++) {
int type;
cin >> type;
if (type == 1) {
ll l, r, c, k;
cin >> l >> r >> c >> k;
group[i] = c;
upd_seg[l].push_back ({i, k});
if (r < n)
upd_seg[r + 1].push_back ({i, 0});
upd_fen[l].push_back ({i, k});
if (r < n)
upd_fen[r + 1].push_back ({i, -k});
}
else if (type == 2) {
ll l, r, k;
cin >> l >> r >> k;
upd_seg[l].push_back ({i, -k});
if (r < n)
upd_seg[r + 1].push_back ({i, 0});
}
else {
ll a, b;
cin >> a >> b;
qry[a].push_back ({i, b});
}
}
segtree balance (q);
fenwick all (q);
for (int i = 0; i <= q; i++)
sol[i] = -1;
for (int i = 1; i <= n; i++) {
for (auto it : upd_seg[i])
balance.update (1, 1, q, it.first, it.second);
for (auto it : upd_fen[i])
all.upd (it.first, it.second);
for (auto it : qry[i]) {
int best = balance.query (1, 1, q, 1, it.first).sum_max;
if (best >= it.second) {
sol[it.first] = group[all.kth (all.qry (it.first) - (best - it.second))];
}
else {
sol[it.first] = 0;
}
}
}
for (int i = 1; i <= q; i++)
if (sol[i] >= 0)
cout << sol[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18184 KB |
Output is correct |
2 |
Correct |
14 ms |
18208 KB |
Output is correct |
3 |
Correct |
13 ms |
18076 KB |
Output is correct |
4 |
Correct |
13 ms |
18260 KB |
Output is correct |
5 |
Correct |
13 ms |
18144 KB |
Output is correct |
6 |
Correct |
13 ms |
18124 KB |
Output is correct |
7 |
Correct |
14 ms |
18208 KB |
Output is correct |
8 |
Correct |
14 ms |
18252 KB |
Output is correct |
9 |
Correct |
14 ms |
18188 KB |
Output is correct |
10 |
Correct |
13 ms |
18180 KB |
Output is correct |
11 |
Correct |
14 ms |
18208 KB |
Output is correct |
12 |
Correct |
13 ms |
18252 KB |
Output is correct |
13 |
Correct |
13 ms |
18156 KB |
Output is correct |
14 |
Correct |
13 ms |
18100 KB |
Output is correct |
15 |
Correct |
12 ms |
18080 KB |
Output is correct |
16 |
Correct |
13 ms |
18252 KB |
Output is correct |
17 |
Correct |
13 ms |
18192 KB |
Output is correct |
18 |
Correct |
13 ms |
18208 KB |
Output is correct |
19 |
Correct |
14 ms |
18208 KB |
Output is correct |
20 |
Correct |
13 ms |
18252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18184 KB |
Output is correct |
2 |
Correct |
14 ms |
18208 KB |
Output is correct |
3 |
Correct |
13 ms |
18076 KB |
Output is correct |
4 |
Correct |
13 ms |
18260 KB |
Output is correct |
5 |
Correct |
13 ms |
18144 KB |
Output is correct |
6 |
Correct |
13 ms |
18124 KB |
Output is correct |
7 |
Correct |
14 ms |
18208 KB |
Output is correct |
8 |
Correct |
14 ms |
18252 KB |
Output is correct |
9 |
Correct |
14 ms |
18188 KB |
Output is correct |
10 |
Correct |
13 ms |
18180 KB |
Output is correct |
11 |
Correct |
14 ms |
18208 KB |
Output is correct |
12 |
Correct |
13 ms |
18252 KB |
Output is correct |
13 |
Correct |
13 ms |
18156 KB |
Output is correct |
14 |
Correct |
13 ms |
18100 KB |
Output is correct |
15 |
Correct |
12 ms |
18080 KB |
Output is correct |
16 |
Correct |
13 ms |
18252 KB |
Output is correct |
17 |
Correct |
13 ms |
18192 KB |
Output is correct |
18 |
Correct |
13 ms |
18208 KB |
Output is correct |
19 |
Correct |
14 ms |
18208 KB |
Output is correct |
20 |
Correct |
13 ms |
18252 KB |
Output is correct |
21 |
Incorrect |
14 ms |
18192 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
27588 KB |
Output is correct |
2 |
Correct |
105 ms |
29512 KB |
Output is correct |
3 |
Correct |
105 ms |
28792 KB |
Output is correct |
4 |
Correct |
95 ms |
28740 KB |
Output is correct |
5 |
Correct |
103 ms |
29452 KB |
Output is correct |
6 |
Correct |
128 ms |
29512 KB |
Output is correct |
7 |
Correct |
45 ms |
25192 KB |
Output is correct |
8 |
Correct |
47 ms |
25660 KB |
Output is correct |
9 |
Correct |
103 ms |
28880 KB |
Output is correct |
10 |
Correct |
95 ms |
29068 KB |
Output is correct |
11 |
Correct |
107 ms |
29016 KB |
Output is correct |
12 |
Correct |
107 ms |
29112 KB |
Output is correct |
13 |
Correct |
94 ms |
28092 KB |
Output is correct |
14 |
Correct |
98 ms |
29360 KB |
Output is correct |
15 |
Correct |
105 ms |
30528 KB |
Output is correct |
16 |
Correct |
143 ms |
30672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
464 ms |
52340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18184 KB |
Output is correct |
2 |
Correct |
14 ms |
18208 KB |
Output is correct |
3 |
Correct |
13 ms |
18076 KB |
Output is correct |
4 |
Correct |
13 ms |
18260 KB |
Output is correct |
5 |
Correct |
13 ms |
18144 KB |
Output is correct |
6 |
Correct |
13 ms |
18124 KB |
Output is correct |
7 |
Correct |
14 ms |
18208 KB |
Output is correct |
8 |
Correct |
14 ms |
18252 KB |
Output is correct |
9 |
Correct |
14 ms |
18188 KB |
Output is correct |
10 |
Correct |
13 ms |
18180 KB |
Output is correct |
11 |
Correct |
14 ms |
18208 KB |
Output is correct |
12 |
Correct |
13 ms |
18252 KB |
Output is correct |
13 |
Correct |
13 ms |
18156 KB |
Output is correct |
14 |
Correct |
13 ms |
18100 KB |
Output is correct |
15 |
Correct |
12 ms |
18080 KB |
Output is correct |
16 |
Correct |
13 ms |
18252 KB |
Output is correct |
17 |
Correct |
13 ms |
18192 KB |
Output is correct |
18 |
Correct |
13 ms |
18208 KB |
Output is correct |
19 |
Correct |
14 ms |
18208 KB |
Output is correct |
20 |
Correct |
13 ms |
18252 KB |
Output is correct |
21 |
Correct |
92 ms |
27588 KB |
Output is correct |
22 |
Correct |
105 ms |
29512 KB |
Output is correct |
23 |
Correct |
105 ms |
28792 KB |
Output is correct |
24 |
Correct |
95 ms |
28740 KB |
Output is correct |
25 |
Correct |
103 ms |
29452 KB |
Output is correct |
26 |
Correct |
128 ms |
29512 KB |
Output is correct |
27 |
Correct |
45 ms |
25192 KB |
Output is correct |
28 |
Correct |
47 ms |
25660 KB |
Output is correct |
29 |
Correct |
103 ms |
28880 KB |
Output is correct |
30 |
Correct |
95 ms |
29068 KB |
Output is correct |
31 |
Correct |
107 ms |
29016 KB |
Output is correct |
32 |
Correct |
107 ms |
29112 KB |
Output is correct |
33 |
Correct |
94 ms |
28092 KB |
Output is correct |
34 |
Correct |
98 ms |
29360 KB |
Output is correct |
35 |
Correct |
105 ms |
30528 KB |
Output is correct |
36 |
Correct |
143 ms |
30672 KB |
Output is correct |
37 |
Correct |
106 ms |
27656 KB |
Output is correct |
38 |
Correct |
91 ms |
26988 KB |
Output is correct |
39 |
Correct |
40 ms |
24444 KB |
Output is correct |
40 |
Correct |
47 ms |
25644 KB |
Output is correct |
41 |
Correct |
99 ms |
28672 KB |
Output is correct |
42 |
Correct |
97 ms |
28920 KB |
Output is correct |
43 |
Correct |
100 ms |
28892 KB |
Output is correct |
44 |
Correct |
126 ms |
28868 KB |
Output is correct |
45 |
Correct |
103 ms |
28876 KB |
Output is correct |
46 |
Correct |
97 ms |
28872 KB |
Output is correct |
47 |
Correct |
56 ms |
26192 KB |
Output is correct |
48 |
Correct |
77 ms |
28604 KB |
Output is correct |
49 |
Correct |
74 ms |
25784 KB |
Output is correct |
50 |
Correct |
88 ms |
27332 KB |
Output is correct |
51 |
Correct |
99 ms |
29092 KB |
Output is correct |
52 |
Correct |
99 ms |
29104 KB |
Output is correct |
53 |
Correct |
84 ms |
27916 KB |
Output is correct |
54 |
Correct |
112 ms |
30828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
26824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18184 KB |
Output is correct |
2 |
Correct |
14 ms |
18208 KB |
Output is correct |
3 |
Correct |
13 ms |
18076 KB |
Output is correct |
4 |
Correct |
13 ms |
18260 KB |
Output is correct |
5 |
Correct |
13 ms |
18144 KB |
Output is correct |
6 |
Correct |
13 ms |
18124 KB |
Output is correct |
7 |
Correct |
14 ms |
18208 KB |
Output is correct |
8 |
Correct |
14 ms |
18252 KB |
Output is correct |
9 |
Correct |
14 ms |
18188 KB |
Output is correct |
10 |
Correct |
13 ms |
18180 KB |
Output is correct |
11 |
Correct |
14 ms |
18208 KB |
Output is correct |
12 |
Correct |
13 ms |
18252 KB |
Output is correct |
13 |
Correct |
13 ms |
18156 KB |
Output is correct |
14 |
Correct |
13 ms |
18100 KB |
Output is correct |
15 |
Correct |
12 ms |
18080 KB |
Output is correct |
16 |
Correct |
13 ms |
18252 KB |
Output is correct |
17 |
Correct |
13 ms |
18192 KB |
Output is correct |
18 |
Correct |
13 ms |
18208 KB |
Output is correct |
19 |
Correct |
14 ms |
18208 KB |
Output is correct |
20 |
Correct |
13 ms |
18252 KB |
Output is correct |
21 |
Incorrect |
14 ms |
18192 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18184 KB |
Output is correct |
2 |
Correct |
14 ms |
18208 KB |
Output is correct |
3 |
Correct |
13 ms |
18076 KB |
Output is correct |
4 |
Correct |
13 ms |
18260 KB |
Output is correct |
5 |
Correct |
13 ms |
18144 KB |
Output is correct |
6 |
Correct |
13 ms |
18124 KB |
Output is correct |
7 |
Correct |
14 ms |
18208 KB |
Output is correct |
8 |
Correct |
14 ms |
18252 KB |
Output is correct |
9 |
Correct |
14 ms |
18188 KB |
Output is correct |
10 |
Correct |
13 ms |
18180 KB |
Output is correct |
11 |
Correct |
14 ms |
18208 KB |
Output is correct |
12 |
Correct |
13 ms |
18252 KB |
Output is correct |
13 |
Correct |
13 ms |
18156 KB |
Output is correct |
14 |
Correct |
13 ms |
18100 KB |
Output is correct |
15 |
Correct |
12 ms |
18080 KB |
Output is correct |
16 |
Correct |
13 ms |
18252 KB |
Output is correct |
17 |
Correct |
13 ms |
18192 KB |
Output is correct |
18 |
Correct |
13 ms |
18208 KB |
Output is correct |
19 |
Correct |
14 ms |
18208 KB |
Output is correct |
20 |
Correct |
13 ms |
18252 KB |
Output is correct |
21 |
Incorrect |
14 ms |
18192 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |