#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, ll>> join[N][2];
vector<pair<int, ll>> leave[N][2];
vector<pair<int, ll>> 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 |
31324 KB |
Output is correct |
2 |
Correct |
14 ms |
31324 KB |
Output is correct |
3 |
Correct |
14 ms |
31380 KB |
Output is correct |
4 |
Correct |
14 ms |
31580 KB |
Output is correct |
5 |
Correct |
14 ms |
31320 KB |
Output is correct |
6 |
Correct |
14 ms |
31320 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
14 ms |
31580 KB |
Output is correct |
9 |
Correct |
14 ms |
31508 KB |
Output is correct |
10 |
Correct |
14 ms |
31324 KB |
Output is correct |
11 |
Correct |
14 ms |
31324 KB |
Output is correct |
12 |
Correct |
14 ms |
31576 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
14 ms |
31324 KB |
Output is correct |
16 |
Correct |
14 ms |
31324 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
15 ms |
31384 KB |
Output is correct |
19 |
Correct |
15 ms |
31580 KB |
Output is correct |
20 |
Correct |
16 ms |
31580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31324 KB |
Output is correct |
2 |
Correct |
14 ms |
31324 KB |
Output is correct |
3 |
Correct |
14 ms |
31380 KB |
Output is correct |
4 |
Correct |
14 ms |
31580 KB |
Output is correct |
5 |
Correct |
14 ms |
31320 KB |
Output is correct |
6 |
Correct |
14 ms |
31320 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
14 ms |
31580 KB |
Output is correct |
9 |
Correct |
14 ms |
31508 KB |
Output is correct |
10 |
Correct |
14 ms |
31324 KB |
Output is correct |
11 |
Correct |
14 ms |
31324 KB |
Output is correct |
12 |
Correct |
14 ms |
31576 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
14 ms |
31324 KB |
Output is correct |
16 |
Correct |
14 ms |
31324 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
15 ms |
31384 KB |
Output is correct |
19 |
Correct |
15 ms |
31580 KB |
Output is correct |
20 |
Correct |
16 ms |
31580 KB |
Output is correct |
21 |
Incorrect |
15 ms |
31324 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
38736 KB |
Output is correct |
2 |
Correct |
64 ms |
39400 KB |
Output is correct |
3 |
Correct |
69 ms |
38660 KB |
Output is correct |
4 |
Correct |
67 ms |
38740 KB |
Output is correct |
5 |
Correct |
65 ms |
39460 KB |
Output is correct |
6 |
Correct |
66 ms |
39248 KB |
Output is correct |
7 |
Correct |
54 ms |
36920 KB |
Output is correct |
8 |
Correct |
57 ms |
37044 KB |
Output is correct |
9 |
Correct |
58 ms |
38484 KB |
Output is correct |
10 |
Correct |
60 ms |
38992 KB |
Output is correct |
11 |
Correct |
63 ms |
38740 KB |
Output is correct |
12 |
Correct |
61 ms |
38992 KB |
Output is correct |
13 |
Correct |
70 ms |
38420 KB |
Output is correct |
14 |
Correct |
80 ms |
39248 KB |
Output is correct |
15 |
Correct |
72 ms |
40020 KB |
Output is correct |
16 |
Correct |
68 ms |
40272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
114 ms |
36088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31324 KB |
Output is correct |
2 |
Correct |
14 ms |
31324 KB |
Output is correct |
3 |
Correct |
14 ms |
31380 KB |
Output is correct |
4 |
Correct |
14 ms |
31580 KB |
Output is correct |
5 |
Correct |
14 ms |
31320 KB |
Output is correct |
6 |
Correct |
14 ms |
31320 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
14 ms |
31580 KB |
Output is correct |
9 |
Correct |
14 ms |
31508 KB |
Output is correct |
10 |
Correct |
14 ms |
31324 KB |
Output is correct |
11 |
Correct |
14 ms |
31324 KB |
Output is correct |
12 |
Correct |
14 ms |
31576 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
14 ms |
31324 KB |
Output is correct |
16 |
Correct |
14 ms |
31324 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
15 ms |
31384 KB |
Output is correct |
19 |
Correct |
15 ms |
31580 KB |
Output is correct |
20 |
Correct |
16 ms |
31580 KB |
Output is correct |
21 |
Correct |
64 ms |
38736 KB |
Output is correct |
22 |
Correct |
64 ms |
39400 KB |
Output is correct |
23 |
Correct |
69 ms |
38660 KB |
Output is correct |
24 |
Correct |
67 ms |
38740 KB |
Output is correct |
25 |
Correct |
65 ms |
39460 KB |
Output is correct |
26 |
Correct |
66 ms |
39248 KB |
Output is correct |
27 |
Correct |
54 ms |
36920 KB |
Output is correct |
28 |
Correct |
57 ms |
37044 KB |
Output is correct |
29 |
Correct |
58 ms |
38484 KB |
Output is correct |
30 |
Correct |
60 ms |
38992 KB |
Output is correct |
31 |
Correct |
63 ms |
38740 KB |
Output is correct |
32 |
Correct |
61 ms |
38992 KB |
Output is correct |
33 |
Correct |
70 ms |
38420 KB |
Output is correct |
34 |
Correct |
80 ms |
39248 KB |
Output is correct |
35 |
Correct |
72 ms |
40020 KB |
Output is correct |
36 |
Correct |
68 ms |
40272 KB |
Output is correct |
37 |
Correct |
89 ms |
37972 KB |
Output is correct |
38 |
Correct |
73 ms |
37716 KB |
Output is correct |
39 |
Correct |
56 ms |
36392 KB |
Output is correct |
40 |
Correct |
64 ms |
37180 KB |
Output is correct |
41 |
Correct |
90 ms |
38456 KB |
Output is correct |
42 |
Correct |
92 ms |
38992 KB |
Output is correct |
43 |
Correct |
90 ms |
39000 KB |
Output is correct |
44 |
Correct |
90 ms |
38712 KB |
Output is correct |
45 |
Correct |
94 ms |
38976 KB |
Output is correct |
46 |
Correct |
93 ms |
38976 KB |
Output is correct |
47 |
Correct |
85 ms |
37656 KB |
Output is correct |
48 |
Correct |
96 ms |
38484 KB |
Output is correct |
49 |
Correct |
63 ms |
36700 KB |
Output is correct |
50 |
Correct |
75 ms |
37972 KB |
Output is correct |
51 |
Correct |
93 ms |
38996 KB |
Output is correct |
52 |
Correct |
86 ms |
39004 KB |
Output is correct |
53 |
Correct |
55 ms |
38492 KB |
Output is correct |
54 |
Correct |
67 ms |
40276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
149 ms |
32716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31324 KB |
Output is correct |
2 |
Correct |
14 ms |
31324 KB |
Output is correct |
3 |
Correct |
14 ms |
31380 KB |
Output is correct |
4 |
Correct |
14 ms |
31580 KB |
Output is correct |
5 |
Correct |
14 ms |
31320 KB |
Output is correct |
6 |
Correct |
14 ms |
31320 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
14 ms |
31580 KB |
Output is correct |
9 |
Correct |
14 ms |
31508 KB |
Output is correct |
10 |
Correct |
14 ms |
31324 KB |
Output is correct |
11 |
Correct |
14 ms |
31324 KB |
Output is correct |
12 |
Correct |
14 ms |
31576 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
14 ms |
31324 KB |
Output is correct |
16 |
Correct |
14 ms |
31324 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
15 ms |
31384 KB |
Output is correct |
19 |
Correct |
15 ms |
31580 KB |
Output is correct |
20 |
Correct |
16 ms |
31580 KB |
Output is correct |
21 |
Incorrect |
15 ms |
31324 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31324 KB |
Output is correct |
2 |
Correct |
14 ms |
31324 KB |
Output is correct |
3 |
Correct |
14 ms |
31380 KB |
Output is correct |
4 |
Correct |
14 ms |
31580 KB |
Output is correct |
5 |
Correct |
14 ms |
31320 KB |
Output is correct |
6 |
Correct |
14 ms |
31320 KB |
Output is correct |
7 |
Correct |
15 ms |
31324 KB |
Output is correct |
8 |
Correct |
14 ms |
31580 KB |
Output is correct |
9 |
Correct |
14 ms |
31508 KB |
Output is correct |
10 |
Correct |
14 ms |
31324 KB |
Output is correct |
11 |
Correct |
14 ms |
31324 KB |
Output is correct |
12 |
Correct |
14 ms |
31576 KB |
Output is correct |
13 |
Correct |
14 ms |
31324 KB |
Output is correct |
14 |
Correct |
15 ms |
31324 KB |
Output is correct |
15 |
Correct |
14 ms |
31324 KB |
Output is correct |
16 |
Correct |
14 ms |
31324 KB |
Output is correct |
17 |
Correct |
15 ms |
31324 KB |
Output is correct |
18 |
Correct |
15 ms |
31384 KB |
Output is correct |
19 |
Correct |
15 ms |
31580 KB |
Output is correct |
20 |
Correct |
16 ms |
31580 KB |
Output is correct |
21 |
Incorrect |
15 ms |
31324 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |