This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e6 + 7, P = 30001;
struct Rect {
int x1, y1, x2, y2, c;
} a[P];
int p;
struct Event {
int x, l, r, c;
bool operator < (Event e) {
return x < e.x;
}
};
struct Tree {
int n;
int tree[N << 2], prop[N << 2];
void init(int n_) {
n = n_;
memset(tree, 0, sizeof tree);
memset(prop, 0, sizeof prop);
}
int get() {
return tree[0];
}
void gap(int v, int x) {
prop[v] += x;
tree[v] += x;
}
void push(int v) {
gap(v * 2 + 1, prop[v]);
gap(v * 2 + 2, prop[v]);
prop[v] = 0;
}
void relax(int v) {
tree[v] = min(tree[v * 2 + 1], tree[v * 2 + 2]);
}
void add(int v, int tl, int tr, int l, int r, int x) {
if (tr < l || r < tl)
return;
if (l <= tl && tr <= r) {
gap(v, x);
return;
}
int tm = (tl + tr) >> 1;
push(v);
add(v * 2 + 1, tl, tm, l, r, x);
add(v * 2 + 2, tm + 1, tr, l, r, x);
relax(v);
//cout << tl << ' ' << tr << " : " << tree[v] << endl;
}
void add(int l, int r, int x) {
add(0, 1, n, l, r, x);
}
} mag;
const int INF = 2e9 + 7;
bool check(int n, int m, int b, int mid) {
if (mid > m)
return 0;
vector <Event> s;
for (int i = 0; i < p; ++i) {
int x1 = max(1, a[i].x1 - mid + 1);
int y1 = max(1, a[i].y1 - mid + 1);
s.app({x1, y1, a[i].y2, a[i].c});
s.app({a[i].x2 + 1, y1, a[i].y2, -a[i].c});
}
mag.init(m - mid + 1);
sort(all(s));
int cost = INF;
for (int i = 0; i < s.size(); ++i) {
auto e = s[i];
if (e.x + mid - 1 > n)
break;
mag.add(s[i].l, s[i].r, s[i].c);
//cout << m - mid + 1 << endl;
//cout << "add " << s[i].x << ' ' << s[i].l << ' ' << s[i].r << ' ' << s[i].c << endl;
if (i + 1 < s.size() && s[i+1].x == s[i].x)
continue;
cost = min(cost, mag.get());
}
return cost <= b;
}
void LMAO_ROFL_2020(int n, int m, int b) {
swap(n, m);
cin >> p;
for (int i = 0; i < p; ++i) {
cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2 >> a[i].c;
}
int l = 0, r = N;
while (l < r - 1) {
int mid = (l + r) >> 1;
if (check(n, m, b, mid))
l = mid;
else
r = mid;
}
cout << l << endl;
exit(0);
}
namespace LMAO {
const int MAXN = 1e6 + 7;
const int INF = 1e9 + 7;
struct Point {
int x, y;
};
struct Node {
int len, mn, l, r, val, lval, rval, add;
};
Node tree[MAXN * 4];
void calc(int v) {
tree[v].len = tree[v * 2 + 1].len + tree[v * 2 + 2].len;
tree[v].mn = min(tree[v * 2 + 1].mn, tree[v * 2 + 2].mn);
tree[v].lval = tree[v * 2 + 1].lval;
tree[v].rval = tree[v * 2 + 2].rval;
if (tree[v * 2 + 1].l == tree[v * 2 + 1].len && tree[v * 2 + 1].lval == tree[v * 2 + 2].lval) {
tree[v].l = tree[v * 2 + 1].len + tree[v * 2 + 2].l;
}
else {
tree[v].l = tree[v * 2 + 1].l;
}
if (tree[v * 2 + 2].r == tree[v * 2 + 2].len && tree[v * 2 + 1].rval == tree[v * 2 + 2].rval) {
tree[v].r = tree[v * 2 + 2].len + tree[v * 2 + 1].r;
}
else {
tree[v].r = tree[v * 2 + 2].r;
}
tree[v].val = -INF;
if (tree[v * 2 + 1].mn == tree[v].mn) tree[v].val = max(tree[v].val, tree[v * 2 + 1].val);
if (tree[v * 2 + 2].mn == tree[v].mn) tree[v].val = max(tree[v].val, tree[v * 2 + 2].val);
if (tree[v * 2 + 1].rval == tree[v].mn && tree[v * 2 + 2].lval == tree[v].mn) {
tree[v].val = max(tree[v].val, tree[v * 2 + 1].r + tree[v * 2 + 2].l);
}
}
void push(int v) {
tree[v * 2 + 1].add += tree[v].add;
tree[v * 2 + 1].mn += tree[v].add;
tree[v * 2 + 1].lval += tree[v].add;
tree[v * 2 + 1].rval += tree[v].add;
tree[v * 2 + 2].add += tree[v].add;
tree[v * 2 + 2].mn += tree[v].add;
tree[v * 2 + 2].lval += tree[v].add;
tree[v * 2 + 2].rval += tree[v].add;
tree[v].add = 0;
}
void upd(int v, int tl, int tr, int l, int r, int x) {
if (tr < l || r < tl) return;
if (l <= tl && tr <= r) {
tree[v].add += x;
tree[v].lval += x;
tree[v].rval += x;
tree[v].mn += x;
return;
}
int tm = (tl + tr) / 2;
push(v);
upd(v * 2 + 1, tl, tm, l, r, x);
upd(v * 2 + 2, tm + 1, tr, l, r, x);
calc(v);
}
vector <pair <int, int> > add_sc[MAXN];
vector <pair <int, int> > del_sc[MAXN];
bool check(int lx, int rx) {
return (tree[0].mn == 0 && tree[0].val >= rx - lx + 1);
}
void build(int v, int tl, int tr) {
if (tl == tr) {
tree[v].len = 1;
tree[v].mn = 0;
tree[v].l = 1;
tree[v].r = 1;
tree[v].val = 1;
tree[v].lval = 0;
tree[v].rval = 0;
tree[v].add = 0;
return;
}
int tm = (tl + tr) / 2;
build(v * 2 + 1, tl, tm);
build(v * 2 + 2, tm + 1, tr);
calc(v);
}
void myadd(int r, int n) {
for (pair <int, int> e : add_sc[r]) {
upd(0, 1, n, e.first, e.second, 1);
}
}
void mydel(int l, int n) {
for (pair <int, int> e : del_sc[l]) {
upd(0, 1, n, e.first, e.second, -1);
}
}
};
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int m, n;
cin >> m >> n;
int b;
cin >> b;
if (b != 0) {
LMAO_ROFL_2020(n, m, b);
}
using namespace LMAO;
int p;
cin >> p;
vector <pair <Point, Point> > a(p);
for (int i = 0; i < p; ++i) {
cin >> a[i].first.x >> a[i].first.y >> a[i].second.x >> a[i].second.y;
int c;
cin >> c;
}
for (int i = 0; i < p; ++i) {
add_sc[a[i].first.x].push_back({a[i].first.y, a[i].second.y});
del_sc[a[i].second.x + 1].push_back({a[i].first.y, a[i].second.y});
}
build(0, 1, n);
int ans = 0;
int rx = 1;
myadd(1, n);
for (int lx = 1; lx <= m; ++lx) {
if (rx < lx) {
for (int i = rx + 1; i <= lx; ++i) myadd(i, n);
rx = lx;
}
mydel(lx, n);
while (rx <= m && check(lx, rx)) {
++rx;
myadd(rx, n);
}
ans = max(ans, rx - lx);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
pyramid_base.cpp: In function 'bool check(int, int, int, int)':
pyramid_base.cpp:93:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); ++i) {
~~^~~~~~~~~~
pyramid_base.cpp:103:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i + 1 < s.size() && s[i+1].x == s[i].x)
~~~~~~^~~~~~~~~~
# | 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... |