#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ldb;
#define int ll
const int INF = 1e18 + 228;
struct obstacle {
int x1, y1, x2, y2, cost;
};
int n, m;
int p;
int q;
vector<obstacle> obstacles;
const int MAXN = 1e6 + 228;
int tree[4 * MAXN];
int mod[4 * MAXN];
void push(int v, int l, int r) {
tree[v] += mod[v];
if (l + 1 != r) {
mod[2 * v + 1] += mod[v];
mod[2 * v + 2] += mod[v];
}
mod[v] = 0;
}
void add(int v, int l, int r, int ql, int qr, int val) {
push(v, l, r);
if (l >= qr || ql >= r) {
return;
}
if (ql <= l && r <= qr) {
mod[v] += val;
push(v, l, r);
return;
}
int m = (l + r) / 2;
add(2 * v + 1, l, m, ql, qr, val);
add(2 * v + 2, m, r, ql, qr, val);
tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
}
void add(int l, int r, int val) {
add(0, 0, m, l, r, val);
}
int get(int v, int l, int r, int ql, int qr) {
push(v, l, r);
if (l >= qr || ql >= r) {
return INF;
}
if (ql <= l && r <= qr) {
return tree[v];
}
int m = (l + r) / 2;
return min(get(2 * v + 1, l, m, ql, qr), get(2 * v + 2, m, r, ql, qr));
}
int get_mn(int l, int r) {
return get(0, 0, m, l, r);
}
bool canBuild(int r) {
vector<array<int, 4>> qq; // {time, l, r, val}
for (int i = 0; i < q; i++) {
qq.push_back({max(0LL, obstacles[i].x1 - r + 1), max(0LL, obstacles[i].y1 - r + 1), obstacles[i].y2, obstacles[i].cost});
qq.push_back({obstacles[i].x2, max(0LL, obstacles[i].y1 - r + 1), obstacles[i].y2, -obstacles[i].cost});
}
qq.push_back({0, 0, m, 0});
qq.push_back({n, 0, m, 0});
sort(qq.begin(), qq.end());
int last_time = 0;
bool ans = 0;
for (auto el : qq) {
if (el[0] != last_time && last_time + r <= n) {
int el = get_mn(0, m - r + 1);
if (el <= p) {
ans = 1;
}
}
last_time = el[0];
add(el[1], el[2], el[3]);
}
return ans;
}
void solve() {
cin >> n >> m >> p >> q;
obstacles.resize(q);
for (int i = 0; i <q; i++) {
cin >> obstacles[i].x1;
cin >> obstacles[i].y1;
cin >> obstacles[i].x2;
cin >> obstacles[i].y2;
cin >> obstacles[i].cost;
obstacles[i].x1--;
obstacles[i].y1--;
}
int L = 0;
int R = min(n, m) + 1;
while (R - L > 1) {
int M = (L + R) / 2;
if (canBuild(M)) {
L = M;
} else {
R = M;
}
}
cout << L << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
4564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
16468 KB |
Output is correct |
2 |
Correct |
70 ms |
31300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
31540 KB |
Output is correct |
2 |
Correct |
30 ms |
17880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
2008 KB |
Output is correct |
2 |
Correct |
87 ms |
2132 KB |
Output is correct |
3 |
Correct |
64 ms |
1968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
370 ms |
7128 KB |
Output is correct |
2 |
Correct |
421 ms |
7332 KB |
Output is correct |
3 |
Correct |
328 ms |
7120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
956 ms |
37528 KB |
Output is correct |
2 |
Correct |
91 ms |
4704 KB |
Output is correct |
3 |
Correct |
316 ms |
37432 KB |
Output is correct |
4 |
Correct |
1075 ms |
37724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1108 ms |
38236 KB |
Output is correct |
2 |
Correct |
1126 ms |
38240 KB |
Output is correct |
3 |
Correct |
789 ms |
38348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1212 ms |
38896 KB |
Output is correct |
2 |
Correct |
1730 ms |
39156 KB |
Output is correct |
3 |
Correct |
1673 ms |
39136 KB |
Output is correct |
4 |
Correct |
1820 ms |
39280 KB |
Output is correct |
5 |
Correct |
1661 ms |
39132 KB |
Output is correct |
6 |
Correct |
839 ms |
39272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5021 ms |
71804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5050 ms |
96008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5070 ms |
99620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |