#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,ll> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 250005;
struct IT {
vector<ll> tr, lazy;
IT (int sz) : tr(4 * sz), lazy(4 * sz) {}
void apply (int k, ll val) {
tr[k] += val, lazy[k] += val;
}
void pushDown (int k) {
if (!lazy[k]) return;
apply(2 * k, lazy[k]), apply(2 * k + 1, lazy[k]), lazy[k] = 0;
}
void update (int a, int b, ll val, int k, int l, int r) {
if (b < l || r < a) return;
if (a <= l && r <= b)
return apply(k, val), void();
pushDown(k);
int mid = (l + r) >> 1;
update(a, b, val, 2 * k, l, mid);
update(a, b, val, 2 * k + 1, mid + 1, r);
tr[k] = min(tr[2 * k], tr[2 * k + 1]);
}
void walk (ll cur, int k, int l, int r, vector<tt> &vec) {
if (tr[k] >= cur)
return vec.emplace_back(l, r, cur), void();
if (l == r)
return vec.emplace_back(l, r, tr[k]), void();
pushDown(k);
int mid = (l + r) >> 1;
walk(cur, 2 * k, l, mid, vec);
walk(cur, 2 * k + 1, mid + 1, r, vec);
}
void breakDown (int a, int b, ll cur, int k, int l, int r, vector<tt> &vec) {
if (b < l || r < a) return;
if (tr[k] >= cur)
return vec.emplace_back(max(a, l), min(b, r), cur), void();
if (a <= l && r <= b)
return walk(cur, k, l, r, vec), void();
pushDown(k);
int mid = (l + r) >> 1;
breakDown(a, b, cur, 2 * k, l, mid, vec);
breakDown(a, b, cur, 2 * k + 1, mid + 1, r, vec);
}
} tree(mn);
struct BIT {
vector<ll> tr;
BIT (int sz) : tr(sz + 1) {}
int p (int k) { return k & -k; }
void update (int pos, int val) {
for (; pos < tr.size(); pos += p(pos)) tr[pos] += val;
}
ll preSum (int pos) {
ll ans = 0;
for (; pos; pos -= p(pos)) ans += tr[pos];
return ans;
}
int walk (ll ub) {
int ans = 0, lg = 31 - __builtin_clz(tr.size());
ll sum = 0;
for (int msk = (1 << lg); msk > 0; msk >>= 1) {
if ((ans | msk) < tr.size() && tr[ans | msk] + sum < ub) ans |= msk, sum += tr[ans];
}
return ans;
}
} customer(mn), cut(mn);
vector<pl> openCust[mn], openCut[mn], closeCust[mn], closeCut[mn], query[mn];
int group[mn], ans[mn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, q; cin >> n >> m >> q;
for (int i = 1; i <= q; i++) {
int type; cin >> type;
if (type == 1) {
int l, r; ll ppl; cin >> l >> r >> group[i] >> ppl;
openCust[l].emplace_back(i, ppl);
closeCust[r].emplace_back(i, ppl);
tree.update(l, r, ppl, 1, 1, n);
}
else if (type == 2) {
int l, r; ll cut; cin >> l >> r >> cut;
vector<tt> updates;
tree.breakDown(l, r, cut, 1, 1, n, updates);
for (auto [l, r, w] : updates) {
openCut[l].emplace_back(i, w);
closeCut[r].emplace_back(i, w);
tree.update(l, r, -w, 1, 1, n);
}
}
else {
int pos; ll ppl; cin >> pos >> ppl;
query[pos].emplace_back(i, ppl);
}
ans[i] = -1;
}
for (int i = 1; i <= n; i++) {
for (auto [crew, sz] : openCust[i])
customer.update(crew, sz);
for (auto [crew, sz] : openCut[i])
cut.update(crew, sz);
for (auto [moment, ppl] : query[i]) {
ll curCustomer = customer.preSum(moment), leftCustomer = cut.preSum(moment);
if (curCustomer - leftCustomer < ppl) ans[moment] = 0;
else {
int crew = customer.walk(leftCustomer + ppl) + 1;
ans[moment] = group[crew];
}
}
for (auto [crew, sz] : closeCust[i])
customer.update(crew, -sz);
for (auto [crew, sz] : closeCut[i])
cut.update(crew, -sz);
}
for (int i = 1; i <= q; i++)
if (ans[i] != -1) cout << ans[i] << "\n";
return 0;
}
Compilation message
foodcourt.cpp: In member function 'void BIT::update(int, int)':
foodcourt.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (; pos < tr.size(); pos += p(pos)) tr[pos] += val;
| ~~~~^~~~~~~~~~~
foodcourt.cpp: In member function 'int BIT::walk(ll)':
foodcourt.cpp:83:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | if ((ans | msk) < tr.size() && tr[ans | msk] + sum < ub) ans |= msk, sum += tr[ans];
| ~~~~~~~~~~~~^~~~~~~~~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:111:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
111 | for (auto [l, r, w] : updates) {
| ^
foodcourt.cpp:125:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
125 | for (auto [crew, sz] : openCust[i])
| ^
foodcourt.cpp:127:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
127 | for (auto [crew, sz] : openCut[i])
| ^
foodcourt.cpp:130:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
130 | for (auto [moment, ppl] : query[i]) {
| ^
foodcourt.cpp:139:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
139 | for (auto [crew, sz] : closeCust[i])
| ^
foodcourt.cpp:141:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
141 | for (auto [crew, sz] : closeCut[i])
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
50492 KB |
Output is correct |
2 |
Correct |
30 ms |
50780 KB |
Output is correct |
3 |
Correct |
23 ms |
49488 KB |
Output is correct |
4 |
Correct |
24 ms |
49412 KB |
Output is correct |
5 |
Correct |
23 ms |
49500 KB |
Output is correct |
6 |
Correct |
23 ms |
49508 KB |
Output is correct |
7 |
Correct |
28 ms |
50356 KB |
Output is correct |
8 |
Correct |
28 ms |
50000 KB |
Output is correct |
9 |
Correct |
34 ms |
52060 KB |
Output is correct |
10 |
Correct |
28 ms |
50696 KB |
Output is correct |
11 |
Correct |
29 ms |
50460 KB |
Output is correct |
12 |
Correct |
30 ms |
50776 KB |
Output is correct |
13 |
Correct |
23 ms |
49756 KB |
Output is correct |
14 |
Correct |
26 ms |
50416 KB |
Output is correct |
15 |
Correct |
25 ms |
49696 KB |
Output is correct |
16 |
Correct |
33 ms |
51712 KB |
Output is correct |
17 |
Correct |
31 ms |
51292 KB |
Output is correct |
18 |
Correct |
40 ms |
51536 KB |
Output is correct |
19 |
Correct |
27 ms |
50004 KB |
Output is correct |
20 |
Correct |
27 ms |
50268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
50492 KB |
Output is correct |
2 |
Correct |
30 ms |
50780 KB |
Output is correct |
3 |
Correct |
23 ms |
49488 KB |
Output is correct |
4 |
Correct |
24 ms |
49412 KB |
Output is correct |
5 |
Correct |
23 ms |
49500 KB |
Output is correct |
6 |
Correct |
23 ms |
49508 KB |
Output is correct |
7 |
Correct |
28 ms |
50356 KB |
Output is correct |
8 |
Correct |
28 ms |
50000 KB |
Output is correct |
9 |
Correct |
34 ms |
52060 KB |
Output is correct |
10 |
Correct |
28 ms |
50696 KB |
Output is correct |
11 |
Correct |
29 ms |
50460 KB |
Output is correct |
12 |
Correct |
30 ms |
50776 KB |
Output is correct |
13 |
Correct |
23 ms |
49756 KB |
Output is correct |
14 |
Correct |
26 ms |
50416 KB |
Output is correct |
15 |
Correct |
25 ms |
49696 KB |
Output is correct |
16 |
Correct |
33 ms |
51712 KB |
Output is correct |
17 |
Correct |
31 ms |
51292 KB |
Output is correct |
18 |
Correct |
40 ms |
51536 KB |
Output is correct |
19 |
Correct |
27 ms |
50004 KB |
Output is correct |
20 |
Correct |
27 ms |
50268 KB |
Output is correct |
21 |
Correct |
38 ms |
52744 KB |
Output is correct |
22 |
Correct |
29 ms |
50780 KB |
Output is correct |
23 |
Correct |
27 ms |
49496 KB |
Output is correct |
24 |
Correct |
25 ms |
49488 KB |
Output is correct |
25 |
Correct |
23 ms |
49492 KB |
Output is correct |
26 |
Correct |
23 ms |
49496 KB |
Output is correct |
27 |
Correct |
29 ms |
50456 KB |
Output is correct |
28 |
Correct |
26 ms |
49500 KB |
Output is correct |
29 |
Correct |
38 ms |
52556 KB |
Output is correct |
30 |
Correct |
27 ms |
50180 KB |
Output is correct |
31 |
Correct |
40 ms |
53332 KB |
Output is correct |
32 |
Correct |
51 ms |
57168 KB |
Output is correct |
33 |
Correct |
54 ms |
56340 KB |
Output is correct |
34 |
Correct |
31 ms |
51544 KB |
Output is correct |
35 |
Correct |
27 ms |
51028 KB |
Output is correct |
36 |
Correct |
57 ms |
57684 KB |
Output is correct |
37 |
Correct |
25 ms |
49624 KB |
Output is correct |
38 |
Correct |
26 ms |
50000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
250948 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1107 ms |
265544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
50492 KB |
Output is correct |
2 |
Correct |
30 ms |
50780 KB |
Output is correct |
3 |
Correct |
23 ms |
49488 KB |
Output is correct |
4 |
Correct |
24 ms |
49412 KB |
Output is correct |
5 |
Correct |
23 ms |
49500 KB |
Output is correct |
6 |
Correct |
23 ms |
49508 KB |
Output is correct |
7 |
Correct |
28 ms |
50356 KB |
Output is correct |
8 |
Correct |
28 ms |
50000 KB |
Output is correct |
9 |
Correct |
34 ms |
52060 KB |
Output is correct |
10 |
Correct |
28 ms |
50696 KB |
Output is correct |
11 |
Correct |
29 ms |
50460 KB |
Output is correct |
12 |
Correct |
30 ms |
50776 KB |
Output is correct |
13 |
Correct |
23 ms |
49756 KB |
Output is correct |
14 |
Correct |
26 ms |
50416 KB |
Output is correct |
15 |
Correct |
25 ms |
49696 KB |
Output is correct |
16 |
Correct |
33 ms |
51712 KB |
Output is correct |
17 |
Correct |
31 ms |
51292 KB |
Output is correct |
18 |
Correct |
40 ms |
51536 KB |
Output is correct |
19 |
Correct |
27 ms |
50004 KB |
Output is correct |
20 |
Correct |
27 ms |
50268 KB |
Output is correct |
21 |
Execution timed out |
1064 ms |
250948 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
53852 KB |
Output is correct |
2 |
Correct |
83 ms |
54096 KB |
Output is correct |
3 |
Correct |
71 ms |
54352 KB |
Output is correct |
4 |
Correct |
60 ms |
52820 KB |
Output is correct |
5 |
Correct |
65 ms |
53588 KB |
Output is correct |
6 |
Correct |
69 ms |
54400 KB |
Output is correct |
7 |
Correct |
44 ms |
52504 KB |
Output is correct |
8 |
Correct |
42 ms |
52412 KB |
Output is correct |
9 |
Correct |
50 ms |
53408 KB |
Output is correct |
10 |
Correct |
50 ms |
52564 KB |
Output is correct |
11 |
Correct |
60 ms |
53840 KB |
Output is correct |
12 |
Correct |
59 ms |
53820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
50492 KB |
Output is correct |
2 |
Correct |
30 ms |
50780 KB |
Output is correct |
3 |
Correct |
23 ms |
49488 KB |
Output is correct |
4 |
Correct |
24 ms |
49412 KB |
Output is correct |
5 |
Correct |
23 ms |
49500 KB |
Output is correct |
6 |
Correct |
23 ms |
49508 KB |
Output is correct |
7 |
Correct |
28 ms |
50356 KB |
Output is correct |
8 |
Correct |
28 ms |
50000 KB |
Output is correct |
9 |
Correct |
34 ms |
52060 KB |
Output is correct |
10 |
Correct |
28 ms |
50696 KB |
Output is correct |
11 |
Correct |
29 ms |
50460 KB |
Output is correct |
12 |
Correct |
30 ms |
50776 KB |
Output is correct |
13 |
Correct |
23 ms |
49756 KB |
Output is correct |
14 |
Correct |
26 ms |
50416 KB |
Output is correct |
15 |
Correct |
25 ms |
49696 KB |
Output is correct |
16 |
Correct |
33 ms |
51712 KB |
Output is correct |
17 |
Correct |
31 ms |
51292 KB |
Output is correct |
18 |
Correct |
40 ms |
51536 KB |
Output is correct |
19 |
Correct |
27 ms |
50004 KB |
Output is correct |
20 |
Correct |
27 ms |
50268 KB |
Output is correct |
21 |
Correct |
38 ms |
52744 KB |
Output is correct |
22 |
Correct |
29 ms |
50780 KB |
Output is correct |
23 |
Correct |
27 ms |
49496 KB |
Output is correct |
24 |
Correct |
25 ms |
49488 KB |
Output is correct |
25 |
Correct |
23 ms |
49492 KB |
Output is correct |
26 |
Correct |
23 ms |
49496 KB |
Output is correct |
27 |
Correct |
29 ms |
50456 KB |
Output is correct |
28 |
Correct |
26 ms |
49500 KB |
Output is correct |
29 |
Correct |
38 ms |
52556 KB |
Output is correct |
30 |
Correct |
27 ms |
50180 KB |
Output is correct |
31 |
Correct |
40 ms |
53332 KB |
Output is correct |
32 |
Correct |
51 ms |
57168 KB |
Output is correct |
33 |
Correct |
54 ms |
56340 KB |
Output is correct |
34 |
Correct |
31 ms |
51544 KB |
Output is correct |
35 |
Correct |
27 ms |
51028 KB |
Output is correct |
36 |
Correct |
57 ms |
57684 KB |
Output is correct |
37 |
Correct |
25 ms |
49624 KB |
Output is correct |
38 |
Correct |
26 ms |
50000 KB |
Output is correct |
39 |
Execution timed out |
1064 ms |
250948 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
50492 KB |
Output is correct |
2 |
Correct |
30 ms |
50780 KB |
Output is correct |
3 |
Correct |
23 ms |
49488 KB |
Output is correct |
4 |
Correct |
24 ms |
49412 KB |
Output is correct |
5 |
Correct |
23 ms |
49500 KB |
Output is correct |
6 |
Correct |
23 ms |
49508 KB |
Output is correct |
7 |
Correct |
28 ms |
50356 KB |
Output is correct |
8 |
Correct |
28 ms |
50000 KB |
Output is correct |
9 |
Correct |
34 ms |
52060 KB |
Output is correct |
10 |
Correct |
28 ms |
50696 KB |
Output is correct |
11 |
Correct |
29 ms |
50460 KB |
Output is correct |
12 |
Correct |
30 ms |
50776 KB |
Output is correct |
13 |
Correct |
23 ms |
49756 KB |
Output is correct |
14 |
Correct |
26 ms |
50416 KB |
Output is correct |
15 |
Correct |
25 ms |
49696 KB |
Output is correct |
16 |
Correct |
33 ms |
51712 KB |
Output is correct |
17 |
Correct |
31 ms |
51292 KB |
Output is correct |
18 |
Correct |
40 ms |
51536 KB |
Output is correct |
19 |
Correct |
27 ms |
50004 KB |
Output is correct |
20 |
Correct |
27 ms |
50268 KB |
Output is correct |
21 |
Correct |
38 ms |
52744 KB |
Output is correct |
22 |
Correct |
29 ms |
50780 KB |
Output is correct |
23 |
Correct |
27 ms |
49496 KB |
Output is correct |
24 |
Correct |
25 ms |
49488 KB |
Output is correct |
25 |
Correct |
23 ms |
49492 KB |
Output is correct |
26 |
Correct |
23 ms |
49496 KB |
Output is correct |
27 |
Correct |
29 ms |
50456 KB |
Output is correct |
28 |
Correct |
26 ms |
49500 KB |
Output is correct |
29 |
Correct |
38 ms |
52556 KB |
Output is correct |
30 |
Correct |
27 ms |
50180 KB |
Output is correct |
31 |
Correct |
40 ms |
53332 KB |
Output is correct |
32 |
Correct |
51 ms |
57168 KB |
Output is correct |
33 |
Correct |
54 ms |
56340 KB |
Output is correct |
34 |
Correct |
31 ms |
51544 KB |
Output is correct |
35 |
Correct |
27 ms |
51028 KB |
Output is correct |
36 |
Correct |
57 ms |
57684 KB |
Output is correct |
37 |
Correct |
25 ms |
49624 KB |
Output is correct |
38 |
Correct |
26 ms |
50000 KB |
Output is correct |
39 |
Execution timed out |
1064 ms |
250948 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |