#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tree[1 << 21][2];
const ll inf = 0x3f3f3f3f3f3f3f3f;
void update(int le, int ri, ll val, int nodele, int noderi, int node) {
if (le > noderi || ri < nodele)return;
if (le <= nodele && noderi <= ri) {
tree[node][1] += val;
tree[node][0] = (nodele == noderi ? 0 : min(tree[node * 2][0], tree[node * 2 + 1][0])) + tree[node][1];
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];
}
int n, m, b, p;
vector<tuple<int, int, int> > vec[1000005];
bool possi(int k) {
memset(tree, 0, sizeof(tree));
for (int i = 1; i <= n; i++) {
for (auto v : vec[i]) {
int y1, y2, c;
tie(y1, y2, c) = v;
if (c > 0) update(max(1, y1 - k + 1), min(m - k + 1, y2), c, 1, m - k + 1, 1);
}
if (i >= k) {
for (auto v : vec[i - k]) {
int y1, y2, c;
tie(y1, y2, c) = v;
if (c < 0) update(max(1, y1 - k + 1), min(m - k + 1, y2), c, 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);
vec[x1].emplace_back(y1, y2, c);
vec[x2].emplace_back(y1, y2, -c);
}
int le, ri, ans, mid;
le = 1;
ri = 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:40: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:43: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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
56696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
56696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
56884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
56884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
56924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
276 ms |
56924 KB |
Output is correct |
2 |
Correct |
316 ms |
57036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
57036 KB |
Output is correct |
2 |
Correct |
286 ms |
57036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
57208 KB |
Output is correct |
2 |
Correct |
188 ms |
57208 KB |
Output is correct |
3 |
Correct |
185 ms |
57208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
57720 KB |
Output is correct |
2 |
Correct |
514 ms |
57748 KB |
Output is correct |
3 |
Correct |
445 ms |
57752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
480 ms |
58100 KB |
Output is correct |
2 |
Correct |
131 ms |
58104 KB |
Output is correct |
3 |
Correct |
574 ms |
58104 KB |
Output is correct |
4 |
Correct |
704 ms |
58236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
671 ms |
58236 KB |
Output is correct |
2 |
Correct |
1103 ms |
58320 KB |
Output is correct |
3 |
Correct |
389 ms |
58492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
564 ms |
58652 KB |
Output is correct |
2 |
Correct |
1443 ms |
58752 KB |
Output is correct |
3 |
Correct |
1262 ms |
58752 KB |
Output is correct |
4 |
Correct |
1497 ms |
58752 KB |
Output is correct |
5 |
Correct |
1400 ms |
58752 KB |
Output is correct |
6 |
Correct |
364 ms |
58752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5018 ms |
67456 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5026 ms |
71548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5009 ms |
71548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |