#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 0x1fffffffffffffff;
template<class T, class U> bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
#define rep(b) for(ll i = 0; i < b; i++)
#define each(i,a) for(auto&& i : a)
#define all(a) begin(a), end(a)
struct SegTree{
ll n;
vector<ll> data, lazy;
SegTree(ll n): n(n), data(n * 2), lazy(n * 2){}
ll get() const {
return data[1];
}
void add(ll l, ll r, ll val){
if(l < 0) l = 0;
if(r > n) r = n;
l += n;
r += n;
ll L = l, R = r;
for(; L < R; L /= 2, R /= 2){
if(L & 1){
data[L] += val;
lazy[L++] += val;
}
if(R & 1){
data[--R] += val;
lazy[R] += val;
}
}
r--;
while(l /= 2) data[l] = min(data[l * 2], data[l * 2 | 1]) + lazy[l];
while(r /= 2) data[r] = min(data[r * 2], data[r * 2 | 1]) + lazy[r];
}
};
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll m, n, b, p;
cin >> m >> n >> b >> p;
using tuplis = array<ll, 4>;
vector<tuplis> in, out;
rep(p){
ll x1, y1, x2, y2, c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
x1--; y1--;
in.push_back({x1, y1, y2, c});
out.push_back({x2, y1, y2, -c});
}
sort(all(in));
sort(all(out));
auto check = [&](ll x) -> bool {
x--;
SegTree seg(n - x);
ll at1 = 0, at2 = 0;
rep(m - x){
while(at1 < p && in[at1][0] <= i + x){
seg.add(in[at1][1] - x, in[at1][2], in[at1][3]);
at1++;
}
while(at2 < p && out[at2][0] <= i){
seg.add(out[at2][1] - x, out[at2][2], out[at2][3]);
at2++;
}
if(seg.get() <= b) return true;
}
return false;
};
ll ok = 0, ng = min(n, m) + 1;
while(ng - ok > 1){
ll cen = (ok + ng) / 2;
if(check(cen)) ok = cen;
else ng = cen;
}
cout << ok << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
16104 KB |
Output is correct |
2 |
Correct |
372 ms |
32112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
29856 KB |
Output is correct |
2 |
Correct |
59 ms |
16128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1020 KB |
Output is correct |
2 |
Correct |
31 ms |
1220 KB |
Output is correct |
3 |
Correct |
26 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
4308 KB |
Output is correct |
2 |
Correct |
167 ms |
5124 KB |
Output is correct |
3 |
Correct |
142 ms |
5104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
187 ms |
18028 KB |
Output is correct |
2 |
Correct |
25 ms |
2556 KB |
Output is correct |
3 |
Correct |
209 ms |
33516 KB |
Output is correct |
4 |
Correct |
373 ms |
31916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
345 ms |
26588 KB |
Output is correct |
2 |
Correct |
801 ms |
34300 KB |
Output is correct |
3 |
Correct |
155 ms |
18540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
259 ms |
18916 KB |
Output is correct |
2 |
Correct |
985 ms |
34700 KB |
Output is correct |
3 |
Correct |
932 ms |
34708 KB |
Output is correct |
4 |
Correct |
1018 ms |
34768 KB |
Output is correct |
5 |
Correct |
990 ms |
34748 KB |
Output is correct |
6 |
Correct |
127 ms |
19044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3471 ms |
50048 KB |
Output is correct |
2 |
Correct |
295 ms |
19632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5099 ms |
59200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5079 ms |
68424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |