#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000;
struct segment_tree{
int N;
vector<long long> sum, left;
segment_tree(int N2){
N = 1;
while (N < N2){
N *= 2;
}
sum = vector<long long>(N * 2 - 1, INF);
left = vector<long long>(N * 2 - 1, INF);
for (int i = 0; i < N2; i++){
sum[N - 1 + i] = 0;
left[N - 1 + i] = 0;
}
for (int i = N - 2; i >= 0; i--){
sum[i] = sum[i * 2 + 1] + sum[i * 2 + 2];
left[i] = 0;
}
}
void add(int i, long long x){
i += N - 1;
sum[i] += x;
left[i] = sum[i];
while (i > 0){
i = (i - 1) / 2;
sum[i] = sum[i * 2 + 1] + sum[i * 2 + 2];
left[i] = min(left[i * 2 + 1], sum[i * 2 + 1] + min(left[i * 2 + 2], (long long) 0));
}
}
long long get(){
return left[0];
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int M, N;
cin >> M >> N;
int B;
cin >> B;
int P;
cin >> P;
vector<int> X1(P), Y1(P), X2(P), Y2(P), C(P);
for (int i = 0; i < P; i++){
cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i] >> C[i];
X1[i]--;
Y1[i]--;
}
int tv = 0, fv = min(M, N) + 1;
vector<vector<int>> add(N), sub(N);
while (fv - tv > 1){
int mid = (tv + fv) / 2;
for (int i = 0; i < P; i++){
add[max(Y1[i] - mid + 1, 0)].push_back(i);
if (Y2[i] < N - mid + 1){
sub[Y2[i]].push_back(i);
}
}
segment_tree ST(M - mid + 1);
bool ok = false;
for (int i = 0; i < N - mid + 1; i++){
for (int j : add[i]){
ST.add(max(X1[j] - mid + 1, 0), C[j]);
if (X2[j] < M - mid + 1){
ST.add(X2[j], -C[j]);
}
}
add[i].clear();
for (int j : sub[i]){
ST.add(max(X1[j] - mid + 1, 0), -C[j]);
if (X2[j] < M - mid + 1){
ST.add(X2[j], C[j]);
}
}
sub[i].clear();
if (ST.get() <= B){
ok = true;
}
}
if (ok){
tv = mid;
} else {
fv = mid;
}
}
cout << tv << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
9652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
63776 KB |
Output is correct |
2 |
Correct |
498 ms |
80688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
516 ms |
80924 KB |
Output is correct |
2 |
Correct |
279 ms |
63888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1356 KB |
Output is correct |
2 |
Correct |
33 ms |
1976 KB |
Output is correct |
3 |
Correct |
32 ms |
1864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
244 ms |
12096 KB |
Output is correct |
2 |
Correct |
290 ms |
12604 KB |
Output is correct |
3 |
Correct |
253 ms |
12660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
661 ms |
69132 KB |
Output is correct |
2 |
Correct |
220 ms |
34244 KB |
Output is correct |
3 |
Correct |
144 ms |
52560 KB |
Output is correct |
4 |
Correct |
1194 ms |
89488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
839 ms |
84140 KB |
Output is correct |
2 |
Correct |
1209 ms |
91120 KB |
Output is correct |
3 |
Correct |
543 ms |
66700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
683 ms |
70112 KB |
Output is correct |
2 |
Correct |
1532 ms |
94132 KB |
Output is correct |
3 |
Correct |
1576 ms |
94020 KB |
Output is correct |
4 |
Correct |
1730 ms |
94224 KB |
Output is correct |
5 |
Correct |
1614 ms |
93776 KB |
Output is correct |
6 |
Correct |
329 ms |
65804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5101 ms |
123960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5016 ms |
131480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5019 ms |
138328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |