#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 4e5 + 5, MAX_R = 1e6 + 5, INF = 1e18;
int r, c, k, n;
array<int, MAX_N> row1, col1, row2, col2, cost;
struct Node { int min, lazy; };
array<Node, 4 * MAX_R> st;
void propogate(int u) {
st[2 * u].min += st[u].lazy, st[2 * u].lazy += st[u].lazy;
st[2 * u + 1].min += st[u].lazy, st[2 * u + 1].lazy += st[u].lazy;
st[u].lazy = 0;
}
void update(int l, int _r, int x, int u = 1, int lo = 1, int hi = r) {
if (l <= lo && hi <= _r) {
st[u].min += x, st[u].lazy += x;
return;
}
propogate(u);
int mid = (lo + hi) / 2;
if (l <= mid) update(l, _r, x, 2 * u, lo, mid);
if (mid < _r) update(l, _r, x, 2 * u + 1, mid + 1, hi);
st[u].min = min(st[2 * u].min, st[2 * u + 1].min);
}
int query(int l, int _r, int u = 1, int lo = 1, int hi = r) {
if (_r < lo || hi < l) return INF;
if (l <= lo && hi <= _r) return st[u].min;
propogate(u);
int mid = (lo + hi) / 2, ans = INF;
if (l <= mid) ans = min(ans, query(l, _r, 2 * u, lo, mid));
if (mid < _r) ans = min(ans, query(l, _r, 2 * u + 1, mid + 1, hi));
return ans;
}
array<vector<int>, MAX_R> ins, del;
bool check(int s) {
Node zero = {0, 0};
fill(st.begin(), st.end(), zero);
for (int i = 1; i <= c; i++) ins[i].clear(), del[i].clear();
for (int i = 1; i <= n; i++) {
ins[max(col1[i] - s + 1, 1ll)].push_back(i);
del[col2[i]].push_back(i);
}
for (int col = 1; col <= c - s + 1; col++) {
for (int i : ins[col])
update(max(row1[i] - s + 1, 1ll), row2[i], cost[i]);
if (query(1, r - s + 1) <= k) {
// cout << s << " " << col << ": " << query(1, r - s + 1) << endl;
return true;
}
for (int i : del[col])
update(max(row1[i] - s + 1, 1ll), row2[i], -cost[i]);
}
return false;
}
int bin_search() {
int lo = 1, hi = min(r, c);
while (lo != hi) {
int mid = ceil((lo + hi) / (double) 2);
if (check(mid)) lo = mid;
else hi = mid - 1;
}
if (!check(lo)) return 0;
return lo;
}
signed main() {
// freopen("pbs.in", "r", stdin), freopen("pbs.out", "w", stdout);
cin.sync_with_stdio(false), cin.tie(0);
cin >> r >> c >> k >> n;
for (int i = 1; i <= n; i++) cin >> row1[i] >> col1[i] >> row2[i] >> col2[i] >> cost[i];
int ans = bin_search();
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
109908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
109908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
109908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
110160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
110416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
394 ms |
110164 KB |
Output is correct |
2 |
Correct |
1158 ms |
110624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1104 ms |
110676 KB |
Output is correct |
2 |
Correct |
460 ms |
110176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
110424 KB |
Output is correct |
2 |
Correct |
109 ms |
110672 KB |
Output is correct |
3 |
Correct |
108 ms |
110676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
113300 KB |
Output is correct |
2 |
Correct |
330 ms |
113748 KB |
Output is correct |
3 |
Correct |
338 ms |
114120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
481 ms |
116048 KB |
Output is correct |
2 |
Correct |
144 ms |
111700 KB |
Output is correct |
3 |
Correct |
167 ms |
115796 KB |
Output is correct |
4 |
Correct |
1498 ms |
120028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
962 ms |
119332 KB |
Output is correct |
2 |
Correct |
2048 ms |
121908 KB |
Output is correct |
3 |
Correct |
657 ms |
114124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
776 ms |
117592 KB |
Output is correct |
2 |
Correct |
1805 ms |
124700 KB |
Output is correct |
3 |
Correct |
1843 ms |
124560 KB |
Output is correct |
4 |
Correct |
2151 ms |
124740 KB |
Output is correct |
5 |
Correct |
1811 ms |
124368 KB |
Output is correct |
6 |
Correct |
453 ms |
113612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4946 ms |
160692 KB |
Output is correct |
2 |
Correct |
1207 ms |
140560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5028 ms |
171316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5048 ms |
181224 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |