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;
const int mxP=4e5, mxM=1e6;
int m, n, b, p, ans, st[1<<21], lz[1<<21];
vector<array<int, 3>> r1[mxM], r2[mxM+1];
void app(int i, int x) {
st[i]+=x;
lz[i]+=x;
}
void psh(int i) {
app(2*i, lz[i]);
app(2*i+1, lz[i]);
lz[i]=0;
}
void upd(int l1, int r1, int x, int i=1, int l2=0, int r2=n-1) {
if(l1<=l2&&r2<=r1) {
app(i, x);
return;
}
int m2=(l2+r2)/2;
psh(i);
if(l1<=m2)
upd(l1, r1, x, 2*i, l2, m2);
if(m2<r1)
upd(l1, r1, x, 2*i+1, m2+1, r2);
st[i]=min(st[2*i], st[2*i+1]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> m >> n >> b >> p;
for(int i=0, xa, ya, xb, yb, c; i<p; ++i) {
cin >> xa >> ya >> xb >> yb >> c, --xa, --ya, --xb, --yb;
r1[xa].push_back({ya, yb, c});
r2[xb+1].push_back({ya, yb, c});
}
if(1) {
int lb=0, rb=n;
while(lb<rb) {
int mb=(lb+rb+1)/2;
bool ok=0;
memset(st, 0, sizeof(st));
memset(lz, 0, sizeof(lz));
if(mb>1)
upd(n-mb+1, n-1, 3e8);
for(int i=0; i<mb-1; ++i)
for(array<int, 3> a : r1[i])
upd(a[0]-mb+1, a[1], a[2]);
for(int i=0; i<=m-mb&&!ok; ++i) {
for(array<int, 3> a : r1[i+mb-1])
upd(a[0]-mb+1, a[1], a[2]);
for(array<int, 3> a : r2[i])
upd(a[0]-mb+1, a[1], -a[2]);
ok=st[1]<=b;
}
if(ok)
lb=mb;
else
rb=mb-1;
}
ans=lb;
} else {
;
}
cout << ans;
}
# | 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... |