#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<iiii> viiii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF (2e9+10)
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// input
template<class T> void IN(T& x) {cin >> x;}
template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); }
// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const vector<T>& x);
template<class T> void OUT(const T& x) {cout << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);}
template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }
template<class H> void OUTLS(const H& h) {OUTL(h); }
template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); }
// dp
template<class T> bool ckmin(T&a, T&b) { bool bl = a > b; a = min(a,b); return bl;}
template<class T> bool ckmax(T&a, T&b) { bool bl = a < b; a = max(a,b); return bl;}
void program();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
program();
}
//===================//
// begin program //
//===================//
const int MX = 5e5;
const int N = (1<<20);
int n, m, b, p;
int c[MX], X1[MX], X2[MX], Y1[MX], Y2[MX];
// segment tree
int SEG[N*2], LAZ[N*2];
void addSeg(int i, int j, int v, int lazy=0, int l=0, int r=N-1, int p=1) {
SEG[p] += lazy;
LAZ[p] += lazy;
if(j < l || i > r) return;
if(i <= l && j >= r) {
SEG[p] += v;
LAZ[p] += v;
return;
}
int m=(l+r)/2;
addSeg(i,j,v,LAZ[p],l ,m,p*2 );
addSeg(i,j,v,LAZ[p],m+1,r,p*2+1);
LAZ[p] = 0;
SEG[p] = min(SEG[p*2], SEG[p*2+1]);
}
int getSeg(int i, int j, int lazy=0, int l=0, int r=N-1, int p=1) {
SEG[p] += lazy;
LAZ[p] += lazy;
if(j < l || i > r) return INF;
if(i <= l && j >= r) return SEG[p];
int m=(l+r)/2;
int a=getSeg(i,j,LAZ[p],l ,m,p*2 );
int b=getSeg(i,j,LAZ[p],m+1,r,p*2+1);
LAZ[p] = 0;
return min(a,b);
}
bool possible(int w) {
RE(i,p) X1[i] -= w-1;
RE(i,p) Y1[i] -= w-1;
// fill pq
viiii pq;
RE(i,p) {
pq.pb({max(0,X1[i]) ,max(0,Y1[i]),Y2[i],-c[i]});
pq.pb({max(0,X2[i]+1),max(0,Y1[i]),Y2[i], c[i]});
}
sort(all(pq));
// clear segment tree
RE(i,N*2) SEG[i]=LAZ[i]=0;
// sweep line
bool stopAsking = 0;
FOR(pp,pq) {
int cx, lbY, ubY, cost;
tie(cx, lbY, ubY, cost) = pp;
cost = -cost;
if(cx != 0 && cx <= m-w ) {
if(getSeg(0,n-w) <= b) {
RE(i,p) X1[i] += w-1;
RE(i,p) Y1[i] += w-1;
return true;
}
}
addSeg(lbY, ubY, cost);
if(cx != 0 && cx <= m-w) {
if(getSeg(0,n-w) <= b) {
RE(i,p) X1[i] += w-1;
RE(i,p) Y1[i] += w-1;
return true;
}
}
}
RE(i,p) X1[i] += w-1;
RE(i,p) Y1[i] += w-1;
return false;
}
void program() {
IN(m,n,b,p);
RE(i,p) IN(X1[i],Y1[i],X2[i],Y2[i],c[i]);
RE(i,p) X1[i]--, Y1[i]--, X2[i]--, Y2[i]--;
int lb=1, ub=min(n,m);
while(lb != ub) {
int mid=(lb+ub+1)/2;
if(possible(mid)) lb=mid;
else ub=mid-1;
}
OUTL(lb);
}
Compilation message
pyramid_base.cpp: In function 'bool possible(int)':
pyramid_base.cpp:115:10: warning: unused variable 'stopAsking' [-Wunused-variable]
115 | bool stopAsking = 0;
| ^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
16764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
16776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
16800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
16716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
16844 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
16844 KB |
Output is correct |
2 |
Incorrect |
113 ms |
16840 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
16844 KB |
Output is correct |
2 |
Correct |
86 ms |
16848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
17304 KB |
Output is correct |
2 |
Correct |
203 ms |
17256 KB |
Output is correct |
3 |
Correct |
178 ms |
17356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
445 ms |
18108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
616 ms |
18808 KB |
Output is correct |
2 |
Correct |
119 ms |
18816 KB |
Output is correct |
3 |
Incorrect |
245 ms |
18796 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1020 ms |
19280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1093 ms |
19352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5096 ms |
35156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5082 ms |
48436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5054 ms |
53516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |