This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 1, R = min(M, N);
while(L <= R){
ll K = (L + R) / 2; // rect K * K
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, A[i].y1 - K + 1, A[i].x2, 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 << max(0LL, L - 1);
}
Compilation message (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |