#include <bits/stdc++.h>
using namespace std;
namespace fio {
const int BSIZE = 524288;
unsigned char buffer[BSIZE];
auto p = buffer + BSIZE;
inline unsigned char readChar() {
if (p == buffer + BSIZE) {
fread(buffer, 1, BSIZE, stdin);
p = buffer;
}
return *p++;
}
int readInt() {
unsigned char c = readChar();
while (c < '-') {
c = readChar();
}
int ret = 0;
while (c >= '-') {
ret = ret * 10 + c - '0';
c = readChar();
}
return ret;
}
}
typedef long long ll;
ll tree[1 << 21][2];
const ll inf = 0x3f3f3f3f3f3f3f3f;
void push(int nodele, int noderi, int node) {
tree[node][0] += tree[node][1];
if (nodele != noderi) {
tree[node * 2][1] += tree[node][1];
tree[node * 2 + 1][1] += tree[node][1];
}
tree[node][1] = 0;
}
void update(int le, int ri, ll val, int nodele, int noderi, int node) {
if (tree[node][1])push(nodele, noderi, node);
if (le > noderi || ri < nodele)return;
if (le <= nodele && noderi <= ri) {
tree[node][1] = val;
push(nodele, noderi, node);
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]);
}
ll query(int le, int ri, int nodele, int noderi, int node) {
if (tree[node][1])push(nodele, noderi, node);
if (le > noderi || ri < nodele)return inf;
if (le <= nodele && noderi <= ri)return tree[node][0];
int mid = (nodele + noderi) / 2;
return min(query(le, ri, nodele, mid, node * 2), query(le, ri, mid + 1, noderi, node * 2 + 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 && query(1, m - k + 1, 1, m - k + 1, 1) <= b) return true;
}
return false;
}
int main() {
//scanf("%d%d%d%d", &n, &m, &b, &p);
n = fio::readInt();
m = fio::readInt();
b = fio::readInt();
p = fio::readInt();
for (int i = 0; i < p; i++) {
int x1, y1, x2, y2, c;
//scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c);
x1 = fio::readInt();
y1 = fio::readInt();
x2 = fio::readInt();
y2 = fio::readInt();
c = fio::readInt();
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 'unsigned char fio::readChar()':
pyramid_base.cpp:9:9: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
fread(buffer, 1, BSIZE, stdin);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
56696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
56744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
56756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
56900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
56924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
56924 KB |
Output is correct |
2 |
Correct |
377 ms |
56932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
393 ms |
56992 KB |
Output is correct |
2 |
Correct |
293 ms |
56992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
57276 KB |
Output is correct |
2 |
Correct |
201 ms |
57352 KB |
Output is correct |
3 |
Correct |
200 ms |
57352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
356 ms |
57936 KB |
Output is correct |
2 |
Correct |
599 ms |
58132 KB |
Output is correct |
3 |
Correct |
471 ms |
58132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
509 ms |
58704 KB |
Output is correct |
2 |
Correct |
109 ms |
58704 KB |
Output is correct |
3 |
Correct |
676 ms |
58704 KB |
Output is correct |
4 |
Correct |
855 ms |
58704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
889 ms |
58748 KB |
Output is correct |
2 |
Correct |
1532 ms |
58868 KB |
Output is correct |
3 |
Correct |
447 ms |
59004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
705 ms |
59108 KB |
Output is correct |
2 |
Correct |
1864 ms |
59260 KB |
Output is correct |
3 |
Correct |
1734 ms |
59260 KB |
Output is correct |
4 |
Correct |
1793 ms |
59260 KB |
Output is correct |
5 |
Correct |
1769 ms |
59260 KB |
Output is correct |
6 |
Correct |
421 ms |
59260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5071 ms |
67996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5091 ms |
71932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5026 ms |
71932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |