#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct Seg{
int tree[2202000], lazy[2202000];
void init(int i, int l, int r){
tree[i] = lazy[i] = 0;
if (l==r) return;
int m = (l+r)>>1;
init(i<<1, l, m); init(i<<1|1, m+1, r);
}
void propagate(int i, int l, int r){
tree[i] += lazy[i];
if (l!=r) lazy[i<<1] += lazy[i], lazy[i<<1|1] += lazy[i];
lazy[i] = 0;
}
void update(int i, int l, int r, int s, int e, int x){
propagate(i, l, r);
if (r<s || e<l) return;
if (s<=l && r<=e){
lazy[i] += x;
propagate(i, l, r);
return;
}
int m = (l+r)>>1;
update(i<<1, l, m, s, e, x);
update(i<<1|1, m+1, r, s, e, x);
tree[i] = min(tree[i<<1], tree[i<<1|1]);
}
}tree;
struct Query{
int l, r, c;
Query(){}
Query(int _l, int _r, int _c): l(_l), r(_r), c(_c) {}
};
vector<Query> L[1001000], R[1001000];
int n, m, B;
bool calc(int x){
tree.init(1, 1, m-x+1);
for (int i=1;i<=x;i++){
for (auto &p:L[i]){
tree.update(1, 1, m-x+1, max(1, p.l-x+1), min(m-x+1, p.r), p.c);
//if (x==3) printf("%d: %d %d -> %d %d\n", i, p.l, p.r, max(1, p.l-x+1), min(m-x+1, p.r));
}
}
if (tree.tree[1]<=B) return 1;
for (int i=x+1;i<=n;i++){
for (auto &p:R[i-x]){
tree.update(1, 1, m-x+1, max(1, p.l-x+1), min(m-x+1, p.r), p.c);
}
for (auto &p:L[i]){
tree.update(1, 1, m-x+1, max(1, p.l-x+1), min(m-x+1, p.r), p.c);
}
if (tree.tree[1]<=B) return 1;
}
return 0;
}
int main(){
scanf("%d %d %d", &m, &n, &B);
int q;
scanf("%d", &q);
for (int i=0;i<q;i++){
int x1, y1, x2, y2, c;
scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &c);
if (B==0) c = 1;
L[y1].emplace_back(x1, x2, c);
R[y2].emplace_back(x1, x2, -c);
}
int l = 1, r = min(m, n), ans = 0;
while(l<=r){
int mid = (l+r)>>1;
if (calc(mid)) l = mid+1, ans = mid;
else r = mid-1;
}
//printf("YES\n");
//printf("%d\n", calc(3));
printf("%d\n", ans);
return 0;
}
Compilation message
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d %d %d", &m, &n, &B);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
pyramid_base.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
47616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
49356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
55560 KB |
Output is correct |
2 |
Correct |
200 ms |
63716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
63768 KB |
Output is correct |
2 |
Correct |
119 ms |
55504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
47688 KB |
Output is correct |
2 |
Correct |
48 ms |
47920 KB |
Output is correct |
3 |
Correct |
57 ms |
47840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
50228 KB |
Output is correct |
2 |
Correct |
287 ms |
50516 KB |
Output is correct |
3 |
Correct |
224 ms |
50504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
56748 KB |
Output is correct |
2 |
Correct |
169 ms |
64944 KB |
Output is correct |
3 |
Correct |
51 ms |
48856 KB |
Output is correct |
4 |
Correct |
690 ms |
65588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
468 ms |
65256 KB |
Output is correct |
2 |
Correct |
831 ms |
65816 KB |
Output is correct |
3 |
Correct |
241 ms |
57800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
360 ms |
57472 KB |
Output is correct |
2 |
Correct |
1170 ms |
66376 KB |
Output is correct |
3 |
Correct |
1002 ms |
66308 KB |
Output is correct |
4 |
Correct |
1091 ms |
66324 KB |
Output is correct |
5 |
Correct |
1124 ms |
66276 KB |
Output is correct |
6 |
Correct |
160 ms |
58184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4925 ms |
75264 KB |
Output is correct |
2 |
Correct |
1768 ms |
74624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5032 ms |
80156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5040 ms |
84756 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |