#include <bits/stdc++.h>
using namespace std;
int tree[1 << 21][2];
void update(int le, int ri, int val, int nodele, int noderi, int node) {
if (le > noderi || ri < nodele)return;
if (le <= nodele && noderi <= ri) {
tree[node][0] += val;
tree[node][1] += val;
return;
}
int mid = (nodele + noderi) / 2;
update(le, ri, val, nodele, mid, node * 2);
update(le, ri, val, mid + 1, noderi, node * 2 + 1);
tree[node][0] = min(tree[node * 2][0], tree[node * 2 + 1][0]) + tree[node][1];
}
void init(int nodele, int noderi, int node) {
tree[node][0] = tree[node][1] = 0;
if (nodele == noderi) return;
int mid = (nodele + noderi) / 2;
init(nodele, mid, node * 2);
init(mid + 1, noderi, node * 2 + 1);
}
int n, m, b, p;
vector<pair<pair<int,int>,int> > in[1000005], out[1000005];
bool possi(int k) {
init(1, m - k + 1, 1);
for (int i = 1; i <= n; i++) {
for (auto &v : in[i]) update(max(1, v.first.first - k + 1), min(m - k + 1, v.first.second), v.second, 1, m - k + 1, 1);
if (i >= k) for (auto &v : out[i - k]) update(max(1, v.first.first - k + 1), min(m - k + 1, v.first.second), v.second, 1, m - k + 1, 1);
if (i >= k && tree[1][0] <= b) return true;
}
return false;
}
int main() {
scanf("%d%d%d%d", &n, &m, &b, &p);
for (int i = 0; i < p; i++) {
int x1, y1, x2, y2, c;
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c);
in[x1].push_back({ {y1, y2}, b ? c : 1 });
out[x2].push_back({ {y1, y2}, b ? -c : -1 });
}
int le, ri, ans, mid;
le = 1;
ri = min(n,m);
ans = 0;
while (le <= ri) {
mid = (le + ri) / 2;
if (possi(mid)) {
ans = mid;
le = mid + 1;
}
else ri = mid - 1;
}
printf("%d\n", ans);
return 0;
}
Compilation message
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &n, &m, &b, &p);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
47460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
47460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
49564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
55612 KB |
Output is correct |
2 |
Correct |
340 ms |
63860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
325 ms |
63932 KB |
Output is correct |
2 |
Correct |
179 ms |
63932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
63932 KB |
Output is correct |
2 |
Correct |
78 ms |
63932 KB |
Output is correct |
3 |
Correct |
72 ms |
63932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
63932 KB |
Output is correct |
2 |
Correct |
290 ms |
63932 KB |
Output is correct |
3 |
Correct |
312 ms |
63932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
323 ms |
63932 KB |
Output is correct |
2 |
Correct |
64 ms |
63932 KB |
Output is correct |
3 |
Correct |
260 ms |
64612 KB |
Output is correct |
4 |
Correct |
635 ms |
65472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
655 ms |
65648 KB |
Output is correct |
2 |
Correct |
1055 ms |
65648 KB |
Output is correct |
3 |
Correct |
243 ms |
65648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
443 ms |
65648 KB |
Output is correct |
2 |
Correct |
1269 ms |
65788 KB |
Output is correct |
3 |
Correct |
1281 ms |
65788 KB |
Output is correct |
4 |
Correct |
1260 ms |
65788 KB |
Output is correct |
5 |
Correct |
1325 ms |
65788 KB |
Output is correct |
6 |
Correct |
190 ms |
65788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4704 ms |
75524 KB |
Output is correct |
2 |
Correct |
511 ms |
75524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5011 ms |
80468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5034 ms |
85280 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |