#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000;
struct lazy_segment_tree{
int N;
vector<long long> ST, lazy;
lazy_segment_tree(int N2){
N = 1;
while (N < N2){
N *= 2;
}
ST = vector<long long>(N * 2 - 1, INF);
for (int i = 0; i < N2; i++){
ST[N - 1 + i] = 0;
}
for (int i = N - 2; i >= 0; i--){
ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
}
lazy = vector<long long>(N * 2 - 1, 0);
}
void eval(int i){
if (i < N - 1){
lazy[i * 2 + 1] += lazy[i];
lazy[i * 2 + 2] += lazy[i];
}
ST[i] += lazy[i];
lazy[i] = 0;
}
void range_add(int L, int R, int x, int i, int l, int r){
eval(i);
if (r <= L || R <= l){
return;
} else if (L <= l && r <= R){
lazy[i] += x;
eval(i);
} else {
int m = (l + r) / 2;
range_add(L, R, x, i * 2 + 1, l, m);
range_add(L, R, x, i * 2 + 2, m, r);
ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
}
}
void range_add(int L, int R, int x){
range_add(L, R, x, 0, 0, N);
}
long long all(){
eval(0);
return ST[0];
}
};
int main(){
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;
while (fv - tv > 1){
int mid = (tv + fv) / 2;
vector<vector<int>> add(N - mid + 2), sub(N - mid + 2);
for (int i = 0; i < P; i++){
add[max(Y1[i] - mid + 1, 0)].push_back(i);
sub[min(Y2[i], N - mid + 1)].push_back(i);
}
lazy_segment_tree ST(M - mid + 1);
bool ok = false;
for (int i = 0; i < N - mid + 1; i++){
for (int j : add[i]){
ST.range_add(max(X1[j] - mid + 1, 0), min(X2[j], M - mid + 1), C[j]);
}
for (int j : sub[i]){
ST.range_add(max(X1[j] - mid + 1, 0), min(X2[j], M - mid + 1), -C[j]);
}
if (ST.all() <= B){
ok = true;
}
}
if (ok){
tv = mid;
} else {
fv = mid;
}
}
cout << tv << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
40172 KB |
Output is correct |
2 |
Correct |
722 ms |
87188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
706 ms |
80360 KB |
Output is correct |
2 |
Correct |
317 ms |
40296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1088 KB |
Output is correct |
2 |
Correct |
87 ms |
1796 KB |
Output is correct |
3 |
Correct |
91 ms |
1904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
487 ms |
9220 KB |
Output is correct |
2 |
Correct |
711 ms |
12180 KB |
Output is correct |
3 |
Correct |
412 ms |
11796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
825 ms |
41884 KB |
Output is correct |
2 |
Correct |
357 ms |
34488 KB |
Output is correct |
3 |
Correct |
229 ms |
49324 KB |
Output is correct |
4 |
Correct |
1710 ms |
81576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1270 ms |
70796 KB |
Output is correct |
2 |
Correct |
1820 ms |
86576 KB |
Output is correct |
3 |
Correct |
586 ms |
42036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
921 ms |
42696 KB |
Output is correct |
2 |
Correct |
2259 ms |
87688 KB |
Output is correct |
3 |
Correct |
2262 ms |
86960 KB |
Output is correct |
4 |
Correct |
2268 ms |
87132 KB |
Output is correct |
5 |
Correct |
2325 ms |
89272 KB |
Output is correct |
6 |
Correct |
318 ms |
42388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5025 ms |
100672 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5017 ms |
114640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5035 ms |
122960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |