#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
int M, N, P;
array<int, 5> arr[404040];
ll B;
struct segtree {
ll tree[1<<21], lazy[1<<21];
void prop(int v, int st, int ed) {
tree[v] += lazy[v];
if (st != ed) {
lazy[2*v] += lazy[v];
lazy[2*v+1] += lazy[v];
}
lazy[v] = 0;
}
void update(int v, int st, int ed, int lt, int rt, int val) {
prop(v, st, ed);
if (lt > ed || st > rt) return;
if (lt <= st && ed <= rt) {
lazy[v] = val;
prop(v, st, ed);
return;
}
int mid = (st+ed)/2;
update(2*v, st, mid, lt, rt, val);
update(2*v+1, mid+1, ed, lt, rt, val);
tree[v] = min(tree[2*v], tree[2*v+1]);
}
ll get(int v, int st, int ed, int lt, int rt) {
prop(v, st, ed);
if (lt > ed || st > rt) return 1e9;
if (lt <= st && ed <= rt) return tree[v];
int mid = (st+ed)/2;
return min(get(2*v, st, mid, lt, rt), get(2*v+1, mid+1, ed, lt, rt));
}
} seg;
vector<array<int, 3>> add[1010101], rem[1010101];
bool solve(int L) {
for (int i = 0; i <= M-L; i++) add[i].clear();
for (int i = 0; i <= M-L; i++) rem[i].clear();
for (int i = 0; i < (1<<21); i++) seg.tree[i] = seg.lazy[i] = 0;
for (int i = 1; i <= P; i++) {
if (arr[i][0]-L < 0) seg.update(1, 0, N-L, arr[i][1]-L, arr[i][3]-1, +arr[i][4]);
else add[arr[i][0]-L].push_back({arr[i][1]-L, arr[i][3]-1, +arr[i][4]});
rem[arr[i][2]].push_back({arr[i][1]-L, arr[i][3]-1, -arr[i][4]});
}
for (int i = 0; i <= M-L; i++) {
for (auto &[l, r, w] : add[i]) seg.update(1, 0, N-L, l, r, w);
for (auto &[l, r, w] : rem[i]) seg.update(1, 0, N-L, l, r, w);
if (seg.get(1, 0, N-L, 0, N-L) <= B) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> M >> N;
cin >> B >> P;
for (int i = 1; i <= P; i++) {
cin >> arr[i][0] >> arr[i][1] >> arr[i][2] >> arr[i][3] >> arr[i][4];
}
int st = 0, ed = min(M, N);
while (st < ed) {
int mid = (st+ed+1)/2;
if (solve(mid)) st = mid;
else ed = mid-1;
}
cout << st << "\n";
return 0;
}
Compilation message
pyramid_base.cpp: In function 'bool solve(int)':
pyramid_base.cpp:57:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
57 | for (auto &[l, r, w] : add[i]) seg.update(1, 0, N-L, l, r, w);
| ^
pyramid_base.cpp:58:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
58 | for (auto &[l, r, w] : rem[i]) seg.update(1, 0, N-L, l, r, w);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
82520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
82524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
82752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
82900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
82872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
83260 KB |
Output is correct |
2 |
Correct |
251 ms |
83040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
83300 KB |
Output is correct |
2 |
Correct |
100 ms |
83024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
83796 KB |
Output is correct |
2 |
Correct |
82 ms |
83052 KB |
Output is correct |
3 |
Correct |
76 ms |
83280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
86820 KB |
Output is correct |
2 |
Correct |
349 ms |
86164 KB |
Output is correct |
3 |
Correct |
290 ms |
86392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
315 ms |
91728 KB |
Output is correct |
2 |
Correct |
98 ms |
87264 KB |
Output is correct |
3 |
Correct |
145 ms |
85360 KB |
Output is correct |
4 |
Correct |
543 ms |
93012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
581 ms |
94332 KB |
Output is correct |
2 |
Correct |
1040 ms |
94352 KB |
Output is correct |
3 |
Correct |
235 ms |
93948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
437 ms |
96072 KB |
Output is correct |
2 |
Correct |
1579 ms |
97016 KB |
Output is correct |
3 |
Correct |
1344 ms |
96632 KB |
Output is correct |
4 |
Correct |
1274 ms |
96924 KB |
Output is correct |
5 |
Correct |
1412 ms |
96820 KB |
Output is correct |
6 |
Correct |
155 ms |
96596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5091 ms |
122740 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5049 ms |
128312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5061 ms |
134188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |