#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
template<class X, class Y>
bool minz(X &x, const Y &y) {
if (x > y) {
x = y;
return true;
} return false;
}
template<class X, class Y>
bool maxz(X &x, const Y &y) {
if (x < y) {
x = y;
return true;
} return false;
}
const int N = 1e6 + 5;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;
ll n, m, b, p;
namespace sub2{
int tree[N], lazy[N], sz;
vector <piii> add[2 * N], rem[2 * N];
vector <int> co;
void down (int i){
if (!lazy[i]) return;
forr (j, i << 1, (i << 1) | 1){
//cout << i << " " << j << "\n";
tree[j] += lazy[i];
lazy[j] += lazy[i];
}
lazy[i] = 0;
}
void update(int i, int l, int r, int u, int v, int val){
if (l > v || r < u) return;
if (l >= u && r <= v){
//cout << i << " " << l << " " << r << " " << val << "\n";
tree[i] += val;
lazy[i] += val;
return;
}
down(i);
int mid = (l + r) >> 1;
update(i << 1, l, mid, u, v, val);
update(i << 1 | 1, mid + 1, r, u, v, val);
tree[i] = min(tree[i << 1], tree[i << 1 | 1]);
//cout << i << " " << tree[i] << "\n";
}
int get (int i, int l, int r, int u, int v){
if (u > r || v < l) return 2 * mod;
if (l >= u && r <= v) return tree[i];
down(i);
int mid = (l + r) >> 1;
return min(get(i << 1, l, mid, u, v), get(i << 1 | 1, mid + 1, r, u, v));
}
int calc(int len){
if (!len) return 0;
memset (tree, 0, sizeof tree);
memset (lazy, 0, sizeof lazy);
int z = upper_bound(all(co), len) - co.begin();
int res = 2 * mod;
forr (i, 1, n){
int flag = 0;
// cout << i << ":\n";
for (piii t : add[i]){
flag = 1;
int u = upper_bound(all(co), t.nd.nd + len - 1) - co.begin();
int v = lower_bound(all(co), t.nd.st) - co.begin() + 1;
//cout << "add " << t.nd.st << " " << t.nd.nd << " " << v << " " << u << " " << t.st << "\n";
update(1, 1, sz, v, u, t.st);
}
if (i >= len){
for (piii t : rem[i - len]){
flag = 1;
int u = upper_bound(all(co), t.nd.nd + len - 1) - co.begin();
int v = lower_bound(all(co), t.nd.st) - co.begin() + 1;
//cout << "rem " << t.nd.st << " " << t.nd.nd << " " << v << " " << u << "\n";
update(1, 1, sz, v, u, -t.st);
}
}
if (i >= len && flag){
res = min (res, get(1, 1, sz, z, sz));
//cout << tree[1] << "\n";
}
}
return res;
}
void solve(){
forr (i, 1, p){
int x, y, u, v, w;
cin >> x >> y >> u >> v >> w;
add[x].pb({w, {y, v}});
rem[u].pb({w, {y, v}});
co.pb(y);
co.pb(v);
}
co.pb(m);
sort(all(co));
co.erase(unique(all(co)), co.end());
sz = co.size();
//cout << sz << "\n";
// for (int u : co){
// cout << u << " ";
// }
// cout << "\n";
// cout << calc(4) << "\n";
int l = 0, r = min(n, m);
while (l < r){
int mid = (l + r + 1) >> 1;
if (calc(mid) <= b)
l = mid;
else r = mid - 1;
}
cout << l << "\n";
}
}
namespace sub3{
void solve(){
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef hqm
freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
#endif
cin >> n >> m >> b >> p;
if (b > 0) sub2::solve();
else sub3::solve();
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
94292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
94296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
94288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
94288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
94288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
94296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
94280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
102484 KB |
Output is correct |
2 |
Correct |
103 ms |
102588 KB |
Output is correct |
3 |
Correct |
93 ms |
102600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
279 ms |
103456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
395 ms |
104144 KB |
Output is correct |
2 |
Correct |
131 ms |
103888 KB |
Output is correct |
3 |
Incorrect |
125 ms |
103504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
561 ms |
104652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
507 ms |
104928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
94352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
94164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
94288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |