/// B>0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int Nmax=30010, S=(1<<20);
int N, M, B, P, ans;
int C[Nmax];
struct Rectangle {int sx, ex, sy, ey;}A[Nmax], t[Nmax];
struct Line {int x, sy, ey, k;};
class LazyPropagation {
public:
void Update(int l, int r, ll v) {Update(1, 1, S, l, r, v);}
ll Query(int l, int r) {return Query(1, 1, S, l, r);}
void init() {fill(Tree, Tree+2*S, 0); fill(Lazy, Lazy+2*S, 0);}
private:
ll Tree[2*S], Lazy[2*S];
void Propagate(int node, int s, int e) {
Tree[node]+=Lazy[node];
if(s!=e) {
Lazy[2*node]+=Lazy[node];
Lazy[2*node+1]+=Lazy[node];
}
Lazy[node]=0;
return;
}
void Update(int node, int s, int e, int l, int r, int v) {
Propagate(node, s, e);
if(l>e || s>r) return;
if(l<=s && e<=r) {
Lazy[node]+=v;
Propagate(node, s, e);
return;
}
int lch=2*node, rch=lch+1, m=s+e>>1;
Update(lch, s, m, l, r, v); Update(rch, m+1, e, l, r, v);
Tree[node]=min(Tree[lch], Tree[rch]);
}
ll Query(int node, int s, int e, int l, int r) {
Propagate(node, s, e);
if(l>e || s>r) return INT_MAX;
if(l<=s && e<=r) return Tree[node];
int lch=2*node, rch=lch+1, m=s+e>>1;
return min(Query(lch, s, m, l, r), Query(rch, m+1, e, l, r));
}
}T;
bool chk(int x) {
vector<Line> V;
for(int i=1; i<=P; i++) {
t[i]=A[i];
t[i].sx=max(1, A[i].sx-x+1);
t[i].sy=max(1, A[i].sy-x+1);
V.push_back({t[i].sx, t[i].sy, t[i].ey, C[i]});
V.push_back({t[i].ex+1, t[i].sy, t[i].ey, -C[i]});
}
V.push_back({1, 0, 0, 0});
sort(V.begin(), V.end(), [](Line a, Line b) {return a.x<b.x;});
T.init();
for(int i=0; i<V.size(); i++) {
if(V[i].x>N-x+1) break;
T.Update(V[i].sy, V[i].ey, V[i].k);
int j;
for(j=i+1; j<V.size() && V[i].x==V[j].x; j++)
T.Update(V[j].sy, V[j].ey, V[j].k);
if(T.Query(1, M-x+1)<=B) return true;
i=j-1;
}
return false;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>M>>B>>P;
for(int i=1; i<=P; i++) {
cin>>A[i].sx>>A[i].sy>>A[i].ex>>A[i].ey>>C[i];
}
for(int s=1, e=1000000; s<=e;) {
int mid=(s+e)/2;
if(chk(mid)) ans=mid, s=mid+1;
else e=mid-1;
}
cout<<ans;
return 0;
}
Compilation message
pyramid_base.cpp: In member function 'void LazyPropagation::Update(int, int, int, int, int, int)':
pyramid_base.cpp:36:39: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int lch=2*node, rch=lch+1, m=s+e>>1;
| ~^~
pyramid_base.cpp: In member function 'll LazyPropagation::Query(int, int, int, int, int)':
pyramid_base.cpp:44:39: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
44 | int lch=2*node, rch=lch+1, m=s+e>>1;
| ~^~
pyramid_base.cpp: In function 'bool chk(int)':
pyramid_base.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=0; i<V.size(); i++) {
| ~^~~~~~~~~
pyramid_base.cpp:65:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(j=i+1; j<V.size() && V[i].x==V[j].x; j++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
33100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
33100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
33192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
33348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
33228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
33236 KB |
Output is correct |
2 |
Correct |
107 ms |
33228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
33240 KB |
Output is correct |
2 |
Correct |
108 ms |
33340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
33760 KB |
Output is correct |
2 |
Correct |
161 ms |
33776 KB |
Output is correct |
3 |
Correct |
145 ms |
33840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
355 ms |
34676 KB |
Output is correct |
2 |
Correct |
462 ms |
34768 KB |
Output is correct |
3 |
Correct |
386 ms |
35056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
437 ms |
35552 KB |
Output is correct |
2 |
Correct |
403 ms |
35928 KB |
Output is correct |
3 |
Correct |
208 ms |
35932 KB |
Output is correct |
4 |
Correct |
534 ms |
36136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
681 ms |
36104 KB |
Output is correct |
2 |
Correct |
974 ms |
36700 KB |
Output is correct |
3 |
Correct |
451 ms |
36920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
685 ms |
36152 KB |
Output is correct |
2 |
Correct |
1255 ms |
37044 KB |
Output is correct |
3 |
Correct |
1182 ms |
37112 KB |
Output is correct |
4 |
Correct |
1330 ms |
37216 KB |
Output is correct |
5 |
Correct |
1331 ms |
37124 KB |
Output is correct |
6 |
Correct |
489 ms |
37204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
88 ms |
33612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
33720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
90 ms |
33640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |