#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
int n, m, b, p;
struct rType {
int y1;
int y2;
int c;
rType(int yy1 = 0, int yy2 = 0, int cc = 0) : y1(yy1), y2(yy2), c(cc) {};
};
vector<rType> addRect[1000005];
vector<rType> subRect[1000005];
int seg[4000020];
int lazy[4000020];
bool mark[4000020];
void build(int v, int tl, int tr) {
lazy[v] = 0;
seg[v] = 0;
mark[v] = false;
if (tl == tr) return;
int mid = (tl + tr) / 2;
build(2 * v, tl, mid);
build(2 * v + 1, mid + 1, tr);
} void build() { build(1, 0, m - 1); }
void push(int v) {
if (mark[v]) {
lazy[2 * v] += lazy[v];
lazy[2 * v + 1] += lazy[v];
mark[2 * v] = true;
mark[2 * v + 1] = true;
seg[2 * v] += lazy[v];
seg[2 * v + 1] += lazy[v];
lazy[v] = 0;
mark[v] = false;
}
}
void upd(int v, int tl, int tr, int l, int r, int x) {
if (l > r) return;
if (l <= tl && r >= tr) {
lazy[v] += x;
seg[v] += x;
mark[v] = true;
return;
}
push(v);
int mid = (tl + tr) / 2;
upd(2 * v, tl, mid, l, min(r, mid), x);
upd(2 * v + 1, mid + 1, tr, max(l, mid + 1), r, x);
seg[v] = min(seg[2 * v], seg[2 * v + 1]);
} void upd(int l, int r, int x) { upd(1, 0, m - 1, l, r, x); }
int qry(int v, int tl, int tr, int l, int r) {
if (l > r) return 1e9;
if (l <= tl && r >= tr) return seg[v];
push(v);
int mid = (tl + tr) / 2;
return min(qry(2 * v, tl, mid, tl, min(r, mid)), qry(2 * v + 1, mid + 1, tr, max(l, mid + 1), r));
} int qry(int l, int r) { return qry(1, 0, m - 1, l, r); }
bool noDice[1000005][2];
bool check(int p) {
build(1, p-1, m-1);
for (int i = 0; i < p; ++i) {
for (rType r : addRect[i]) {
upd(1, p-1, m-1, max(r.y1, p - 1), min(m - 1, r.y2 + p - 1), r.c);
}
}
if (qry(1, p-1, m-1, p - 1, m - 1) <= b) return true;
for (int i = p; i < n; ++i) {
if (!noDice[i][0] && !noDice[i - p][1]) continue;
for (rType r : addRect[i]) {
upd(1, p-1, m-1, max(r.y1, p - 1), min(m - 1, r.y2 + p - 1), r.c);
}
for (rType r : subRect[i - p]) {
upd(1, p-1, m-1, max(r.y1, p - 1), min(m - 1, r.y2 + p - 1), -r.c);
}
if (qry(1, p-1, m-1, p - 1, m - 1) <= b) return true;
}
return false;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
cin >> b;
cin >> p;
for (int i = 0; i < p; ++i) {
int x1, y1, x2, y2, c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
--x1; --y1; --x2; --y2;
addRect[x1].push_back(rType(y1, y2, c));
noDice[x1][0] = true;
subRect[x2].push_back(rType(y1, y2, c));
noDice[x2][1] = true;
}
int l = 0;
int r = min(m, n);
while (l < r) {
int mid = (l + r + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << l << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
47180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
47176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
47628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
49828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
58152 KB |
Output is correct |
2 |
Correct |
209 ms |
67648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
67532 KB |
Output is correct |
2 |
Correct |
116 ms |
58144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
47656 KB |
Output is correct |
2 |
Correct |
62 ms |
47828 KB |
Output is correct |
3 |
Correct |
54 ms |
47804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
50560 KB |
Output is correct |
2 |
Correct |
277 ms |
50648 KB |
Output is correct |
3 |
Correct |
214 ms |
50496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
255 ms |
59680 KB |
Output is correct |
2 |
Correct |
43 ms |
50416 KB |
Output is correct |
3 |
Correct |
169 ms |
66548 KB |
Output is correct |
4 |
Correct |
464 ms |
69048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
472 ms |
69252 KB |
Output is correct |
2 |
Correct |
813 ms |
69080 KB |
Output is correct |
3 |
Correct |
181 ms |
60116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
326 ms |
60328 KB |
Output is correct |
2 |
Correct |
1036 ms |
69436 KB |
Output is correct |
3 |
Correct |
969 ms |
69412 KB |
Output is correct |
4 |
Correct |
1083 ms |
69420 KB |
Output is correct |
5 |
Correct |
1062 ms |
69540 KB |
Output is correct |
6 |
Correct |
129 ms |
60228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4426 ms |
79128 KB |
Output is correct |
2 |
Correct |
332 ms |
56660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5075 ms |
84144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5079 ms |
88784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |