#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
struct segtree {
using T = long long;
using F = long long;
T e() {
return (long long) 1e18;
}
F id() {
return 0;
}
T op(T a, T b) {
return min(a, b);
}
T mapping(F f, T x) {
return f + x;
}
F composition(F f, F g) {
return f + g;
}
int n;
vector<T> node;
vector<F> lazy;
segtree() : segtree(0) {}
segtree(int _n) {
if (_n <= 1) {
n = _n;
} else {
n = 1 << (32 - __builtin_clz(_n - 1));
}
node.resize(2 * n, e());
lazy.resize(n, id());
}
segtree(vector<T> v) {
if ((int) v.size() <= 1) {
n = (int) v.size();
} else {
n = 1 << (32 - __builtin_clz((int) v.size() - 1));
}
node.resize(2 * n, e());
lazy.resize(n, id());
for (int i = 0; i < (int) v.size(); i++) {
node[i + n] = v[i];
}
for (int i = n - 1; i > 0; i--) {
node[i] = op(node[i * 2], node[i * 2 + 1]);
}
}
void eval(int k) {
node[2 * k] = mapping(lazy[k], node[2 * k]);
node[2 * k + 1] = mapping(lazy[k], node[2 * k + 1]);
if (2 * k < n) {
lazy[2 * k] = composition(lazy[k], lazy[2 * k]);
lazy[2 * k + 1] = composition(lazy[k], lazy[2 * k + 1]);
}
lazy[k] = id();
}
void update(int x, int y, F v, int k, int l, int r) {
if (y <= l || r <= x) {
return;
}
if (x <= l && r <= y) {
node[k] = mapping(v, node[k]);
if (k < n) {
lazy[k] = composition(v, lazy[k]);
}
} else {
eval(k);
update(x, y, v, 2 * k, l, (l + r) / 2);
update(x, y, v, 2 * k + 1, (l + r) / 2, r);
node[k] = op(node[2 * k], node[2 * k + 1]);
}
}
T get(int x, int y, int k, int l, int r) {
if (y <= l || r <= x) {
return e();
}
if (x <= l && r <= y) {
return node[k];
}
eval(k);
T vl = get(x, y, 2 * k, l, (l + r) / 2);
T vr = get(x, y, 2 * k + 1, (l + r) / 2, r);
return op(vl, vr);
}
void update(int x, int y, F v) {
update(x, y, v, 1, 0, n);
}
T get(int x, int y) {
return get(x, y, 1, 0, n);
}
T get(int x) {
return get(x, x + 1, 1, 0, n);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
int d;
cin >> d;
int n;
cin >> n;
vector<tuple<int, int, int, int>> a(n), b(n);
for (int i = 0; i < n; i++) {
int x1, y1, x2, y2, c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
x1--, y1--;
a[i] = make_tuple(x1, y1, y2, c);
b[i] = make_tuple(x2, y1, y2, c);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int hi = min(w, h) + 1;
int lo = 0;
vector<int> mp(w, -1);
while (hi - lo > 1) {
int mid = (hi + lo) / 2;
int aid = 0;
int bid = 0;
int ok = 0;
vector<int> ys;
for (int i = 0; i < n; i++) {
auto [x2, y1, y2, c] = b[i];
y1 = max(0, y1 - mid + 1);
y2 = min(w - mid + 1, y2);
ys.emplace_back(y1);
ys.emplace_back(y2);
}
for (int i = 0; i < n; i++) {
auto [x1, y1, y2, c] = a[i];
y1 = max(0, y1 - mid + 1);
y2 = min(w - mid + 1, y2);
ys.emplace_back(y1);
ys.emplace_back(y2);
}
ys.emplace_back(0);
ys.emplace_back(w - mid + 1);
sort(ys.begin(), ys.end());
ys.resize(unique(ys.begin(), ys.end()) - ys.begin());
int sz = (int) ys.size();
for (int i = 0; i < sz; i++) {
mp[ys[i]] = i;
}
debug(mid, ys);
segtree seg = segtree(vector<long long>(sz - 1));
for (int i = 0; i < h - mid + 1; i++) {
while (bid < n && get<0>(b[bid]) <= i) {
auto [x2, y1, y2, c] = b[bid];
y1 = max(0, y1 - mid + 1);
y2 = min(w - mid + 1, y2);
y1 = mp[y1];
y2 = mp[y2];
seg.update(y1, y2, -c);
bid++;
}
while (aid < n && get<0>(a[aid]) - mid + 1 <= i) {
auto [x1, y1, y2, c] = a[aid];
y1 = max(0, y1 - mid + 1);
y2 = min(w - mid + 1, y2);
y1 = mp[y1];
y2 = mp[y2];
seg.update(y1, y2, c);
aid++;
}
if (seg.node[1] <= d) {
debug(aid, bid, i);
ok = 1;
break;
}
}
if (ok) {
lo = mid;
} else {
hi = mid;
}
}
cout << lo << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
4300 KB |
Output is correct |
2 |
Correct |
79 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
4348 KB |
Output is correct |
2 |
Correct |
21 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
720 KB |
Output is correct |
2 |
Correct |
66 ms |
928 KB |
Output is correct |
3 |
Correct |
64 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
2432 KB |
Output is correct |
2 |
Correct |
323 ms |
2568 KB |
Output is correct |
3 |
Correct |
258 ms |
2820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
6160 KB |
Output is correct |
2 |
Correct |
28 ms |
1900 KB |
Output is correct |
3 |
Correct |
133 ms |
7376 KB |
Output is correct |
4 |
Correct |
358 ms |
7240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
370 ms |
7420 KB |
Output is correct |
2 |
Correct |
645 ms |
7656 KB |
Output is correct |
3 |
Correct |
193 ms |
6084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
362 ms |
6708 KB |
Output is correct |
2 |
Correct |
863 ms |
7948 KB |
Output is correct |
3 |
Correct |
792 ms |
8212 KB |
Output is correct |
4 |
Correct |
850 ms |
8248 KB |
Output is correct |
5 |
Correct |
902 ms |
8136 KB |
Output is correct |
6 |
Correct |
147 ms |
6560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5042 ms |
30200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5054 ms |
34904 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5063 ms |
55864 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |