#include <bits/stdc++.h>
using namespace std;
struct Rect {
int x1;
int y1;
int x2;
int y2;
int cost;
};
const int N = (int) 4e5 + 7;
const int L = (int) 1e6 + 7;
int dimx;
int dimy;
int budget;
int n;
Rect rects[N];
struct Node {
int mn;
int len;
int sol;
int pref;
int suf;
};
Node tree[4 * L];
int lazy[4 * L];
Node operator + (Node a, Node b) {
int mn = min(a.mn, b.mn);
int len = a.len + b.len;
int sol;
int pref;
int suf;
if (a.mn == b.mn) {
sol = max(a.suf + b.pref, max(a.sol, b.sol));
pref = a.pref + b.pref * (a.pref == a.len);
suf = b.suf + a.suf * (b.suf == b.len);
} else {
if (a.mn < b.mn) {
sol = a.sol;
pref = a.pref;
suf = 0;
} else {
sol = b.sol;
pref = 0;
suf = b.suf;
}
}
return {mn, len, sol, pref, suf};
}
void build(int v, int tl, int tr) {
lazy[v] = 0;
if (tl == tr) {
tree[v].mn = 0;
tree[v].len = 1;
tree[v].sol = 1;
tree[v].pref = 1;
tree[v].suf = 1;
return;
}
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
tree[v] = tree[2 * v] + tree[2 * v + 1];
}
void push(int v, int tl, int tr) {
if (lazy[v]) {
tree[v].mn += lazy[v];
if (tl < tr) {
lazy[2 * v] += lazy[v];
lazy[2 * v + 1] += lazy[v];
}
lazy[v] = 0;
}
}
void add(int v, int tl, int tr, int l, int r, int x) {
push(v, tl, tr);
if (tr < l || r < tl) {
return;
}
if (l <= tl && tr <= r) {
lazy[v] += x;
push(v, tl, tr);
return;
}
int tm = (tl + tr) / 2;
add(2 * v, tl, tm, l, r, x);
add(2 * v + 1, tm + 1, tr, l, r, x);
tree[v] = tree[2 * v] + tree[2 * v + 1];
}
void build() {
build(1, 1, dimy);
}
void add(int l, int r, int x) {
add(1, 1, dimy, l, r, x);
}
int get() {
/// cout << tree[1].mn << " " << tree[1].len << " ---> " << tree[1].sol << "\n";
if (tree[1].mn == 0) {
return tree[1].sol;
} else {
return 0;
}
}
vector<int> out[L];
vector<int> in[L];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
/// freopen ("input", "r", stdin);
cin >> dimx >> dimy >> budget >> n;
for (int i = 1; i <= n; i++) {
cin >> rects[i].x1 >> rects[i].y1 >> rects[i].x2 >> rects[i].y2 >> rects[i].cost;
in[rects[i].x1].push_back(i);
out[rects[i].x2].push_back(i);
}
build();
if (budget) {
assert(0);
cout << "I will think later about how to solve this subtask\n";
exit(0);
}
int missed = 0;
int x2 = 0, sol = 0;
for (int x1 = 1; x1 <= dimx; x1++) {
/// assert(x2 - x1 + 1 <= get());
if (x2 >= x1 - 1) {
for (auto &i : out[x1 - 1]) {
add(rects[i].y1, rects[i].y2, -1);
///cout << " - " << i << "\n";
}
}
x2 = max(x2, x1 - 1);
/*if (x1 % 10000 == 0) {
cout << "= " << x1 << " " << missed << " : " << sol << "\n";
}*/
/// cout << tree[1].mn << " ----> ";
while (x2 + 1 <= dimx && x2 - x1 + 1 <= get()) {
x2++;
for (auto &i : in[x2]) {
add(rects[i].y1, rects[i].y2, +1);
}
/*if (x1 == 6 && x2 == 5) {
cout << x2 - x1 + 1 << " vs " << get() << "\n";
exit(0);
}*/
if (x2 - x1 + 1 > get()) {
if (x1 == x2) {
break;
}
for (auto &i : in[x2]) {
add(rects[i].y1, rects[i].y2, -1);
}
missed++;
x2--;
break;
}
/**for (auto &i : in[x2]) {
cout << " + " << i << "\n";
}**/
}
if (x2 - x1 + 1 > get()) {
assert(x1 == x2);
// cout << x1 << " " << x2 << " : " << get() << "\n";
} else {
sol = max(sol, x2 - x1 + 1);
}
}
cout << sol << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
47180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
47328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
48124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
53516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5037 ms |
96552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
482 ms |
96708 KB |
Output is correct |
2 |
Execution timed out |
5044 ms |
96508 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
62 ms |
97896 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
76 ms |
110504 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
151 ms |
198868 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
152 ms |
199616 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
155 ms |
200524 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1427 ms |
111832 KB |
Output is correct |
2 |
Correct |
566 ms |
63576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1643 ms |
118636 KB |
Output is correct |
2 |
Execution timed out |
5079 ms |
114840 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1974 ms |
125004 KB |
Output is correct |
2 |
Correct |
1381 ms |
122588 KB |
Output is correct |
3 |
Correct |
1395 ms |
122432 KB |
Output is correct |
4 |
Execution timed out |
5074 ms |
120192 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |