#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));
in.push_back({INF, 0, 0, 0});
out.push_back({INF, 0, 0, 0});
auto check = [&](ll x) -> bool {
x--;
SegTree seg(n - x);
ll i1 = 0, i2 = 0, at = 0;
while(at < m - x){
while(in[i1][0] <= at + x){
seg.add(in[i1][1] - x, in[i1][2], in[i1][3]);
i1++;
}
while(out[i2][0] <= at){
seg.add(out[i2][1] - x, out[i2][2], out[i2][3]);
i2++;
}
if(seg.get() <= b) return true;
at = min(in[i1][0] - x, out[i2][0]);
}
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
16128 KB |
Output is correct |
2 |
Correct |
293 ms |
32012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
29916 KB |
Output is correct |
2 |
Correct |
41 ms |
16128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
896 KB |
Output is correct |
2 |
Correct |
29 ms |
1092 KB |
Output is correct |
3 |
Correct |
26 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
3796 KB |
Output is correct |
2 |
Correct |
179 ms |
4768 KB |
Output is correct |
3 |
Correct |
129 ms |
4720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
17508 KB |
Output is correct |
2 |
Correct |
20 ms |
2164 KB |
Output is correct |
3 |
Correct |
218 ms |
33144 KB |
Output is correct |
4 |
Correct |
339 ms |
31180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
25684 KB |
Output is correct |
2 |
Correct |
707 ms |
33632 KB |
Output is correct |
3 |
Correct |
147 ms |
17760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
18148 KB |
Output is correct |
2 |
Correct |
903 ms |
33816 KB |
Output is correct |
3 |
Correct |
863 ms |
33820 KB |
Output is correct |
4 |
Correct |
916 ms |
33884 KB |
Output is correct |
5 |
Correct |
912 ms |
33908 KB |
Output is correct |
6 |
Correct |
122 ms |
18148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3424 ms |
44204 KB |
Output is correct |
2 |
Correct |
278 ms |
14380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5066 ms |
50752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5075 ms |
56780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |