#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]) {
int num = get(1, t).sum - get(1, t).pre;
cerr << "service: " << t << ' ' << b << '\n';
cerr << get(1, t).sum << ' ' << '\n';
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:124:30: warning: unused variable 'k' [-Wunused-variable]
124 | int t = o.first, k = o.second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31320 KB |
Output is correct |
2 |
Correct |
17 ms |
31576 KB |
Output is correct |
3 |
Correct |
15 ms |
31324 KB |
Output is correct |
4 |
Correct |
14 ms |
31576 KB |
Output is correct |
5 |
Correct |
14 ms |
31324 KB |
Output is correct |
6 |
Correct |
14 ms |
31324 KB |
Output is correct |
7 |
Correct |
16 ms |
31580 KB |
Output is correct |
8 |
Correct |
15 ms |
31484 KB |
Output is correct |
9 |
Correct |
16 ms |
31576 KB |
Output is correct |
10 |
Correct |
16 ms |
31580 KB |
Output is correct |
11 |
Correct |
16 ms |
31364 KB |
Output is correct |
12 |
Correct |
15 ms |
31540 KB |
Output is correct |
13 |
Correct |
15 ms |
31324 KB |
Output is correct |
14 |
Correct |
17 ms |
31336 KB |
Output is correct |
15 |
Correct |
15 ms |
31324 KB |
Output is correct |
16 |
Correct |
16 ms |
31328 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
16 ms |
31832 KB |
Output is correct |
19 |
Correct |
15 ms |
31484 KB |
Output is correct |
20 |
Correct |
15 ms |
31580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31320 KB |
Output is correct |
2 |
Correct |
17 ms |
31576 KB |
Output is correct |
3 |
Correct |
15 ms |
31324 KB |
Output is correct |
4 |
Correct |
14 ms |
31576 KB |
Output is correct |
5 |
Correct |
14 ms |
31324 KB |
Output is correct |
6 |
Correct |
14 ms |
31324 KB |
Output is correct |
7 |
Correct |
16 ms |
31580 KB |
Output is correct |
8 |
Correct |
15 ms |
31484 KB |
Output is correct |
9 |
Correct |
16 ms |
31576 KB |
Output is correct |
10 |
Correct |
16 ms |
31580 KB |
Output is correct |
11 |
Correct |
16 ms |
31364 KB |
Output is correct |
12 |
Correct |
15 ms |
31540 KB |
Output is correct |
13 |
Correct |
15 ms |
31324 KB |
Output is correct |
14 |
Correct |
17 ms |
31336 KB |
Output is correct |
15 |
Correct |
15 ms |
31324 KB |
Output is correct |
16 |
Correct |
16 ms |
31328 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
16 ms |
31832 KB |
Output is correct |
19 |
Correct |
15 ms |
31484 KB |
Output is correct |
20 |
Correct |
15 ms |
31580 KB |
Output is correct |
21 |
Incorrect |
14 ms |
31324 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
39504 KB |
Output is correct |
2 |
Correct |
62 ms |
40276 KB |
Output is correct |
3 |
Correct |
62 ms |
39584 KB |
Output is correct |
4 |
Correct |
59 ms |
39516 KB |
Output is correct |
5 |
Correct |
63 ms |
40272 KB |
Output is correct |
6 |
Correct |
59 ms |
40372 KB |
Output is correct |
7 |
Correct |
53 ms |
36892 KB |
Output is correct |
8 |
Correct |
57 ms |
36944 KB |
Output is correct |
9 |
Correct |
67 ms |
39508 KB |
Output is correct |
10 |
Correct |
62 ms |
39760 KB |
Output is correct |
11 |
Correct |
63 ms |
39764 KB |
Output is correct |
12 |
Correct |
60 ms |
39772 KB |
Output is correct |
13 |
Correct |
65 ms |
38992 KB |
Output is correct |
14 |
Correct |
78 ms |
39944 KB |
Output is correct |
15 |
Correct |
58 ms |
40788 KB |
Output is correct |
16 |
Correct |
74 ms |
41140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
118 ms |
34500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31320 KB |
Output is correct |
2 |
Correct |
17 ms |
31576 KB |
Output is correct |
3 |
Correct |
15 ms |
31324 KB |
Output is correct |
4 |
Correct |
14 ms |
31576 KB |
Output is correct |
5 |
Correct |
14 ms |
31324 KB |
Output is correct |
6 |
Correct |
14 ms |
31324 KB |
Output is correct |
7 |
Correct |
16 ms |
31580 KB |
Output is correct |
8 |
Correct |
15 ms |
31484 KB |
Output is correct |
9 |
Correct |
16 ms |
31576 KB |
Output is correct |
10 |
Correct |
16 ms |
31580 KB |
Output is correct |
11 |
Correct |
16 ms |
31364 KB |
Output is correct |
12 |
Correct |
15 ms |
31540 KB |
Output is correct |
13 |
Correct |
15 ms |
31324 KB |
Output is correct |
14 |
Correct |
17 ms |
31336 KB |
Output is correct |
15 |
Correct |
15 ms |
31324 KB |
Output is correct |
16 |
Correct |
16 ms |
31328 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
16 ms |
31832 KB |
Output is correct |
19 |
Correct |
15 ms |
31484 KB |
Output is correct |
20 |
Correct |
15 ms |
31580 KB |
Output is correct |
21 |
Correct |
75 ms |
39504 KB |
Output is correct |
22 |
Correct |
62 ms |
40276 KB |
Output is correct |
23 |
Correct |
62 ms |
39584 KB |
Output is correct |
24 |
Correct |
59 ms |
39516 KB |
Output is correct |
25 |
Correct |
63 ms |
40272 KB |
Output is correct |
26 |
Correct |
59 ms |
40372 KB |
Output is correct |
27 |
Correct |
53 ms |
36892 KB |
Output is correct |
28 |
Correct |
57 ms |
36944 KB |
Output is correct |
29 |
Correct |
67 ms |
39508 KB |
Output is correct |
30 |
Correct |
62 ms |
39760 KB |
Output is correct |
31 |
Correct |
63 ms |
39764 KB |
Output is correct |
32 |
Correct |
60 ms |
39772 KB |
Output is correct |
33 |
Correct |
65 ms |
38992 KB |
Output is correct |
34 |
Correct |
78 ms |
39944 KB |
Output is correct |
35 |
Correct |
58 ms |
40788 KB |
Output is correct |
36 |
Correct |
74 ms |
41140 KB |
Output is correct |
37 |
Correct |
90 ms |
38640 KB |
Output is correct |
38 |
Correct |
74 ms |
38320 KB |
Output is correct |
39 |
Correct |
55 ms |
36288 KB |
Output is correct |
40 |
Correct |
64 ms |
37056 KB |
Output is correct |
41 |
Correct |
93 ms |
39000 KB |
Output is correct |
42 |
Correct |
100 ms |
39504 KB |
Output is correct |
43 |
Correct |
85 ms |
39480 KB |
Output is correct |
44 |
Correct |
91 ms |
39504 KB |
Output is correct |
45 |
Correct |
87 ms |
39508 KB |
Output is correct |
46 |
Correct |
86 ms |
39868 KB |
Output is correct |
47 |
Correct |
85 ms |
37828 KB |
Output is correct |
48 |
Correct |
90 ms |
38280 KB |
Output is correct |
49 |
Correct |
60 ms |
37204 KB |
Output is correct |
50 |
Correct |
82 ms |
38488 KB |
Output is correct |
51 |
Correct |
90 ms |
39760 KB |
Output is correct |
52 |
Correct |
86 ms |
39760 KB |
Output is correct |
53 |
Correct |
50 ms |
38996 KB |
Output is correct |
54 |
Correct |
60 ms |
41040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
31960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31320 KB |
Output is correct |
2 |
Correct |
17 ms |
31576 KB |
Output is correct |
3 |
Correct |
15 ms |
31324 KB |
Output is correct |
4 |
Correct |
14 ms |
31576 KB |
Output is correct |
5 |
Correct |
14 ms |
31324 KB |
Output is correct |
6 |
Correct |
14 ms |
31324 KB |
Output is correct |
7 |
Correct |
16 ms |
31580 KB |
Output is correct |
8 |
Correct |
15 ms |
31484 KB |
Output is correct |
9 |
Correct |
16 ms |
31576 KB |
Output is correct |
10 |
Correct |
16 ms |
31580 KB |
Output is correct |
11 |
Correct |
16 ms |
31364 KB |
Output is correct |
12 |
Correct |
15 ms |
31540 KB |
Output is correct |
13 |
Correct |
15 ms |
31324 KB |
Output is correct |
14 |
Correct |
17 ms |
31336 KB |
Output is correct |
15 |
Correct |
15 ms |
31324 KB |
Output is correct |
16 |
Correct |
16 ms |
31328 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
16 ms |
31832 KB |
Output is correct |
19 |
Correct |
15 ms |
31484 KB |
Output is correct |
20 |
Correct |
15 ms |
31580 KB |
Output is correct |
21 |
Incorrect |
14 ms |
31324 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31320 KB |
Output is correct |
2 |
Correct |
17 ms |
31576 KB |
Output is correct |
3 |
Correct |
15 ms |
31324 KB |
Output is correct |
4 |
Correct |
14 ms |
31576 KB |
Output is correct |
5 |
Correct |
14 ms |
31324 KB |
Output is correct |
6 |
Correct |
14 ms |
31324 KB |
Output is correct |
7 |
Correct |
16 ms |
31580 KB |
Output is correct |
8 |
Correct |
15 ms |
31484 KB |
Output is correct |
9 |
Correct |
16 ms |
31576 KB |
Output is correct |
10 |
Correct |
16 ms |
31580 KB |
Output is correct |
11 |
Correct |
16 ms |
31364 KB |
Output is correct |
12 |
Correct |
15 ms |
31540 KB |
Output is correct |
13 |
Correct |
15 ms |
31324 KB |
Output is correct |
14 |
Correct |
17 ms |
31336 KB |
Output is correct |
15 |
Correct |
15 ms |
31324 KB |
Output is correct |
16 |
Correct |
16 ms |
31328 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
16 ms |
31832 KB |
Output is correct |
19 |
Correct |
15 ms |
31484 KB |
Output is correct |
20 |
Correct |
15 ms |
31580 KB |
Output is correct |
21 |
Incorrect |
14 ms |
31324 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |