#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll S = (1 << 21);
struct LazySegTree{
ll T[2 * S] = {};
ll lazy[2 * S] = {};
void update(ll l, ll r, ll v) {update(1, 1, S, l, r, v);}
ll query(ll l, ll r) {return query(1, 1, S, l, r);}
void propagate(ll node, ll s, ll e){
ll lch = 2 * node, rch = 2 * node + 1;
if(s != e){
lazy[lch] += lazy[node], lazy[rch] += lazy[node];
}
T[node] += lazy[node];
lazy[node] = 0;
}
void update(ll node, ll s, ll e, ll l, ll r, ll v){
propagate(node, s, e);
if(e < l || s > r) return;
if(l <= s && e <= r){
lazy[node] += v;
propagate(node, s, e);
return;
}
ll lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2;
update(lch, s, m, l, r, v);
update(rch, m + 1, e, l, r, v);
T[node] = min(T[lch], T[rch]);
}
ll query(ll node, ll s, ll e, ll l, ll r){
propagate(node, s, e);
if(e < l || s > r) return 1e15;
if(l <= s && e <= r) return T[node];
ll lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2;
ll x = query(lch, s, m, l, r), y = query(rch, m + 1, e, l, r);
return min(x, y);
}
};
ll M, N;
struct Rect{
ll x1, y1, x2, y2, c;
bool operator<(const Rect &r)const{
return x1 < r.x1;
}
};
ll P, B;
Rect A[400005];
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> M >> N >> B >> P;
for(int i = 1; i <= P; i++){
cin >> A[i].x1 >> A[i].y1 >> A[i].x2 >> A[i].y2 >> A[i].c;
}
LazySegTree LST;
ll L = 0, R = min(M, N);
while(L <= R){
ll K = (L + R) / 2;
vector<ll> Y;
vector<Rect> T;
ll ans = 1e15;
for(int i = 1; i <= P; i++){
T.push_back({A[i].x1 - K + 1, A[i].y1 - K + 1, A[i].x1 - K + 1, A[i].y2, A[i].c});
T.push_back({A[i].x2 + 1, A[i].y1 - K + 1, A[i].x2 + 1, A[i].y2, -A[i].c});
}
for(int i = 0; i < T.size(); i++){
T[i].y1 = max(T[i].y1, 1LL);
T[i].y2 = min(T[i].y2, N);
}
sort(T.begin(), T.end());
ll last = 0;
for(int i = 1; i <= M - K + 1; i++){
while(last < T.size() && T[last].x1 <= i){
LST.update(T[last].y1, T[last].y2, T[last].c);
last++;
}
ans = min(ans, LST.query(1, N - K + 1));
}
while(last < T.size()){
LST.update(T[last].y1, T[last].y2, T[last].c);
last++;
}
if(ans <= B){
L = K + 1;
} else {
R = K - 1;
}
}
cout << L - 1;
}
Compilation message
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0; i < T.size(); i++){
| ~~^~~~~~~~~~
pyramid_base.cpp:77:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<Rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | while(last < T.size() && T[last].x1 <= i){
| ~~~~~^~~~~~~~~~
pyramid_base.cpp:83:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<Rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | while(last < T.size()){
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
65868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
65952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
66000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
66136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
66176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
557 ms |
66168 KB |
Output is correct |
2 |
Correct |
2281 ms |
66224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2170 ms |
66276 KB |
Output is correct |
2 |
Correct |
811 ms |
66244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
67204 KB |
Output is correct |
2 |
Correct |
116 ms |
67216 KB |
Output is correct |
3 |
Correct |
109 ms |
67216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
465 ms |
69036 KB |
Output is correct |
2 |
Correct |
555 ms |
69108 KB |
Output is correct |
3 |
Correct |
503 ms |
69068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1624 ms |
70888 KB |
Output is correct |
2 |
Correct |
3473 ms |
71012 KB |
Output is correct |
3 |
Correct |
315 ms |
70892 KB |
Output is correct |
4 |
Correct |
2908 ms |
71056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2148 ms |
71480 KB |
Output is correct |
2 |
Correct |
3131 ms |
71484 KB |
Output is correct |
3 |
Correct |
1450 ms |
71496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1661 ms |
72056 KB |
Output is correct |
2 |
Correct |
3385 ms |
72068 KB |
Output is correct |
3 |
Correct |
3444 ms |
72308 KB |
Output is correct |
4 |
Correct |
3412 ms |
72216 KB |
Output is correct |
5 |
Correct |
3443 ms |
72228 KB |
Output is correct |
6 |
Correct |
1077 ms |
72136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5091 ms |
110124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5091 ms |
139468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5087 ms |
143188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |