#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = (1 << 18);
#define cerr if (false) cout
struct node {
ll sum = 0;
ll pre = 0;
};
node tr[2 * N];
node combine(node a, node b) {
node res;
res.sum = a.sum + b.sum;
res.pre = min(a.pre, a.sum + b.pre);
return res;
}
void update(int pos, ll val) {
// cerr << "upd: " << pos << ' ' << val << '\n';
tr[pos += N] = {val, min(0ll, val)};
for (pos >>= 1; pos; pos >>= 1)
tr[pos] = combine(tr[2 * pos], tr[2 * pos + 1]);
// cerr << "tree: " << tr[1].sum << ' ' << tr[1].pre << '\n';
}
node get(int ql, int qr, int l = 0, int r = N - 1, int v = 1) {
if (r < ql || l > qr)
return node();
if (ql <= l && r <= qr)
return tr[v];
int m = (l + r) / 2;
return combine(get(ql, qr, l, m, 2 * v), get(ql, qr, m + 1, r, 2 * v + 1));
}
ll cnt[2 * N];
void add(int v, ll a) {
for (cnt[v += N] += a; v > 1; v >>= 1)
cnt[v >> 1] = cnt[v] + cnt[v^1];
}
ll count(int ql, int qr, int l = 0, int r = N - 1, int v = 1) {
if (r < ql || l > qr)
return 0;
if (ql <= l && r <= qr)
return cnt[v];
int m = (l + r) / 2;
return count(ql, qr, l, m, 2 * v) + count(ql, qr, m + 1, r, 2 * v + 1);
}
int n, m, q;
vector<pair<int, int>> join[N][2];
vector<pair<int, int>> leave[N][2];
vector<pair<int, int>> service[N];
map<int, int> timeToGroup;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for (int t = 1; t <= q; t++) {
int type;
cin >> type;
if (type == 1) {
int l, r, k, c;
cin >> l >> r >> c >> k;
timeToGroup[t] = c;
join[l][0].push_back({t, k});
join[r][1].push_back({t, k});
}
if (type == 2) {
int l, r, k;
cin >> l >> r >> k;
leave[l][0].push_back({t, k});
leave[r][1].push_back({t, k});
}
if (type == 3) {
int a, b;
cin >> a >> b;
service[a].push_back({t, b});
}
}
vector<int> res(q + 1, -2);
for (int i = 1; i <= n; i++) {
for (auto o : join[i][0]) {
int t = o.first, k = o.second;
update(t, +k);
add(t, +k);
}
for (auto o : leave[i][0]) {
int t = o.first, k = o.second;
update(t, -k);
}
for (auto [t, b] : service[i]) {
ll num = get(1, t).sum - get(1, t).pre;
if (num < b) {
res[t] = 0;
continue;
}
int l = 0, r = t + 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (count(m, t) >= num - b + 1)
l = m;
else
r = m;
}
res[t] = timeToGroup[l];
}
for (auto o : join[i][1]) {
int t = o.first, k = o.second;
update(t, 0);
add(t, -k);
}
for (auto o : leave[i][1]) {
int t = o.first, k = o.second;
update(t, 0);
}
}
for (int i = 1; i <= q; i++) {
if (res[i] != -2)
cout << res[i] << '\n';
}
}
Compilation message
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:122:30: warning: unused variable 'k' [-Wunused-variable]
122 | int t = o.first, k = o.second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31320 KB |
Output is correct |
2 |
Correct |
16 ms |
31324 KB |
Output is correct |
3 |
Correct |
16 ms |
31460 KB |
Output is correct |
4 |
Correct |
15 ms |
31580 KB |
Output is correct |
5 |
Correct |
16 ms |
31324 KB |
Output is correct |
6 |
Correct |
15 ms |
31324 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
15 ms |
31324 KB |
Output is correct |
9 |
Correct |
16 ms |
31324 KB |
Output is correct |
10 |
Correct |
22 ms |
31492 KB |
Output is correct |
11 |
Correct |
14 ms |
31560 KB |
Output is correct |
12 |
Correct |
16 ms |
31324 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
17 ms |
31344 KB |
Output is correct |
16 |
Correct |
14 ms |
31320 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
14 ms |
31320 KB |
Output is correct |
19 |
Correct |
17 ms |
31320 KB |
Output is correct |
20 |
Correct |
14 ms |
31576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31320 KB |
Output is correct |
2 |
Correct |
16 ms |
31324 KB |
Output is correct |
3 |
Correct |
16 ms |
31460 KB |
Output is correct |
4 |
Correct |
15 ms |
31580 KB |
Output is correct |
5 |
Correct |
16 ms |
31324 KB |
Output is correct |
6 |
Correct |
15 ms |
31324 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
15 ms |
31324 KB |
Output is correct |
9 |
Correct |
16 ms |
31324 KB |
Output is correct |
10 |
Correct |
22 ms |
31492 KB |
Output is correct |
11 |
Correct |
14 ms |
31560 KB |
Output is correct |
12 |
Correct |
16 ms |
31324 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
17 ms |
31344 KB |
Output is correct |
16 |
Correct |
14 ms |
31320 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
14 ms |
31320 KB |
Output is correct |
19 |
Correct |
17 ms |
31320 KB |
Output is correct |
20 |
Correct |
14 ms |
31576 KB |
Output is correct |
21 |
Incorrect |
13 ms |
31320 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
38492 KB |
Output is correct |
2 |
Correct |
59 ms |
39000 KB |
Output is correct |
3 |
Correct |
63 ms |
38480 KB |
Output is correct |
4 |
Correct |
58 ms |
38488 KB |
Output is correct |
5 |
Correct |
65 ms |
38992 KB |
Output is correct |
6 |
Correct |
67 ms |
38992 KB |
Output is correct |
7 |
Correct |
68 ms |
36040 KB |
Output is correct |
8 |
Correct |
58 ms |
36304 KB |
Output is correct |
9 |
Correct |
63 ms |
38352 KB |
Output is correct |
10 |
Correct |
57 ms |
38484 KB |
Output is correct |
11 |
Correct |
58 ms |
38488 KB |
Output is correct |
12 |
Correct |
56 ms |
38484 KB |
Output is correct |
13 |
Correct |
66 ms |
37972 KB |
Output is correct |
14 |
Correct |
70 ms |
38972 KB |
Output is correct |
15 |
Correct |
60 ms |
39504 KB |
Output is correct |
16 |
Correct |
75 ms |
39788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
34296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31320 KB |
Output is correct |
2 |
Correct |
16 ms |
31324 KB |
Output is correct |
3 |
Correct |
16 ms |
31460 KB |
Output is correct |
4 |
Correct |
15 ms |
31580 KB |
Output is correct |
5 |
Correct |
16 ms |
31324 KB |
Output is correct |
6 |
Correct |
15 ms |
31324 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
15 ms |
31324 KB |
Output is correct |
9 |
Correct |
16 ms |
31324 KB |
Output is correct |
10 |
Correct |
22 ms |
31492 KB |
Output is correct |
11 |
Correct |
14 ms |
31560 KB |
Output is correct |
12 |
Correct |
16 ms |
31324 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
17 ms |
31344 KB |
Output is correct |
16 |
Correct |
14 ms |
31320 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
14 ms |
31320 KB |
Output is correct |
19 |
Correct |
17 ms |
31320 KB |
Output is correct |
20 |
Correct |
14 ms |
31576 KB |
Output is correct |
21 |
Correct |
58 ms |
38492 KB |
Output is correct |
22 |
Correct |
59 ms |
39000 KB |
Output is correct |
23 |
Correct |
63 ms |
38480 KB |
Output is correct |
24 |
Correct |
58 ms |
38488 KB |
Output is correct |
25 |
Correct |
65 ms |
38992 KB |
Output is correct |
26 |
Correct |
67 ms |
38992 KB |
Output is correct |
27 |
Correct |
68 ms |
36040 KB |
Output is correct |
28 |
Correct |
58 ms |
36304 KB |
Output is correct |
29 |
Correct |
63 ms |
38352 KB |
Output is correct |
30 |
Correct |
57 ms |
38484 KB |
Output is correct |
31 |
Correct |
58 ms |
38488 KB |
Output is correct |
32 |
Correct |
56 ms |
38484 KB |
Output is correct |
33 |
Correct |
66 ms |
37972 KB |
Output is correct |
34 |
Correct |
70 ms |
38972 KB |
Output is correct |
35 |
Correct |
60 ms |
39504 KB |
Output is correct |
36 |
Correct |
75 ms |
39788 KB |
Output is correct |
37 |
Correct |
93 ms |
37712 KB |
Output is correct |
38 |
Correct |
76 ms |
37456 KB |
Output is correct |
39 |
Correct |
59 ms |
35536 KB |
Output is correct |
40 |
Correct |
72 ms |
36448 KB |
Output is correct |
41 |
Correct |
96 ms |
37968 KB |
Output is correct |
42 |
Correct |
89 ms |
38508 KB |
Output is correct |
43 |
Correct |
85 ms |
38552 KB |
Output is correct |
44 |
Correct |
86 ms |
38236 KB |
Output is correct |
45 |
Correct |
90 ms |
38484 KB |
Output is correct |
46 |
Correct |
97 ms |
38480 KB |
Output is correct |
47 |
Correct |
84 ms |
36812 KB |
Output is correct |
48 |
Correct |
90 ms |
37212 KB |
Output is correct |
49 |
Correct |
62 ms |
36444 KB |
Output is correct |
50 |
Correct |
76 ms |
37676 KB |
Output is correct |
51 |
Correct |
94 ms |
38740 KB |
Output is correct |
52 |
Correct |
87 ms |
38736 KB |
Output is correct |
53 |
Correct |
53 ms |
37972 KB |
Output is correct |
54 |
Correct |
60 ms |
39760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
144 ms |
32276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31320 KB |
Output is correct |
2 |
Correct |
16 ms |
31324 KB |
Output is correct |
3 |
Correct |
16 ms |
31460 KB |
Output is correct |
4 |
Correct |
15 ms |
31580 KB |
Output is correct |
5 |
Correct |
16 ms |
31324 KB |
Output is correct |
6 |
Correct |
15 ms |
31324 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
15 ms |
31324 KB |
Output is correct |
9 |
Correct |
16 ms |
31324 KB |
Output is correct |
10 |
Correct |
22 ms |
31492 KB |
Output is correct |
11 |
Correct |
14 ms |
31560 KB |
Output is correct |
12 |
Correct |
16 ms |
31324 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
17 ms |
31344 KB |
Output is correct |
16 |
Correct |
14 ms |
31320 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
14 ms |
31320 KB |
Output is correct |
19 |
Correct |
17 ms |
31320 KB |
Output is correct |
20 |
Correct |
14 ms |
31576 KB |
Output is correct |
21 |
Incorrect |
13 ms |
31320 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31320 KB |
Output is correct |
2 |
Correct |
16 ms |
31324 KB |
Output is correct |
3 |
Correct |
16 ms |
31460 KB |
Output is correct |
4 |
Correct |
15 ms |
31580 KB |
Output is correct |
5 |
Correct |
16 ms |
31324 KB |
Output is correct |
6 |
Correct |
15 ms |
31324 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
15 ms |
31324 KB |
Output is correct |
9 |
Correct |
16 ms |
31324 KB |
Output is correct |
10 |
Correct |
22 ms |
31492 KB |
Output is correct |
11 |
Correct |
14 ms |
31560 KB |
Output is correct |
12 |
Correct |
16 ms |
31324 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
17 ms |
31344 KB |
Output is correct |
16 |
Correct |
14 ms |
31320 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
14 ms |
31320 KB |
Output is correct |
19 |
Correct |
17 ms |
31320 KB |
Output is correct |
20 |
Correct |
14 ms |
31576 KB |
Output is correct |
21 |
Incorrect |
13 ms |
31320 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |