이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define y1 asdf
#define y2 asdfasd
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
const int MAXN = 1130013;
int N, M, K, B;
struct rect
{
int cost;
int x1, y1, x2, y2;
};
rect arr[MAXN];
vpi ins[MAXN], del[MAXN];
int seg[2 * MAXN], lazy[2 * MAXN];
void push(int w, int L, int R)
{
if (lazy[w] == 0) return;
seg[w] += lazy[w];
if (L != R)
{
lazy[w << 1] += lazy[w];
lazy[w << 1 | 1] += lazy[w];
}
lazy[w] = 0;
return;
}
void update(int w, int L, int R, int a, int b, int v)
{
// if (w == 1)
// {
// cerr << a << ' ' << b << ' ' << v << endl;
// }
push(w, L, R);
if (b < L || R < a) return;
if (a <= L && R <= b)
{
lazy[w] += v;
push(w, L, R);
return;
}
int mid = (L + R) >> 1;
update(w << 1, L, mid, a, b, v);
update(w << 1 | 1, mid + 1, R, a, b, v);
seg[w] = min(seg[w << 1], seg[w << 1 | 1]);
}
bool check(int x)
{
//[ai...ai + x - 1][bi...bi + x - 1].
//in a segment tree, store:
//mins, dp[x][y] = longest lengths of mins
//0...x - 2
int sz = (1 << (33 - __builtin_clz(M - x + 1)));
fill(seg, seg + sz + 1, 0);
fill(lazy, lazy + sz + 1, 0);
// cerr << "TEST " << x << endl;
FOR(i, 0, x - 1)
{
for (auto p : ins[i])
{
update(1, 0, M - x, max(0, p.fi - x + 1), p.se, 1);
}
}
FOR(i, 0, N - x + 1)
{
// cerr << "pos " << i << endl;
for (auto p : ins[i + x - 1])
{
update(1, 0, M - x, max(0, p.fi - x + 1), p.se, 1);
}
if (seg[1] == 0) return true;
for (auto p : del[i])
{
update(1, 0, M - x, max(0, p.fi - x + 1), p.se, -1);
}
}
return false;
}
int32_t main()
{
cout << fixed << setprecision(12);
cerr << fixed << setprecision(4);
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N >> M >> B >> K;
FOR(i, 0, K)
{
int x1, y1, x2, y2, cost;
cin >> x1 >> y1 >> x2 >> y2 >> cost;
x1--; y1--; x2--; y2--;
ins[x1].PB({y1, y2});
del[x2].PB({y1, y2});
// cerr << "insert " << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << endl;
}
int lo = 0, hi = min(N, M);
while(hi > lo)
{
int mid = (hi + lo + 1) >> 1;
if (check(mid)) lo = mid;
else hi = mid - 1;
}
cout << lo << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |