/// B>0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int Nmax=400010, 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 |
33144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
33144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
33188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
33368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
33240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
33248 KB |
Output is correct |
2 |
Correct |
108 ms |
33228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
33228 KB |
Output is correct |
2 |
Correct |
104 ms |
33228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
33764 KB |
Output is correct |
2 |
Correct |
167 ms |
33740 KB |
Output is correct |
3 |
Correct |
150 ms |
33744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
361 ms |
34732 KB |
Output is correct |
2 |
Correct |
476 ms |
34680 KB |
Output is correct |
3 |
Correct |
389 ms |
34676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
433 ms |
35656 KB |
Output is correct |
2 |
Correct |
374 ms |
35520 KB |
Output is correct |
3 |
Correct |
196 ms |
35540 KB |
Output is correct |
4 |
Correct |
537 ms |
35512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
794 ms |
35884 KB |
Output is correct |
2 |
Correct |
960 ms |
35892 KB |
Output is correct |
3 |
Correct |
462 ms |
36000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
682 ms |
36324 KB |
Output is correct |
2 |
Correct |
1328 ms |
36244 KB |
Output is correct |
3 |
Correct |
1211 ms |
36208 KB |
Output is correct |
4 |
Correct |
1306 ms |
36260 KB |
Output is correct |
5 |
Correct |
1299 ms |
36388 KB |
Output is correct |
6 |
Correct |
545 ms |
36184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5091 ms |
59460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5049 ms |
77240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5012 ms |
86816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |