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 <stdio.h>
#include <string.h>
#define N_ (1 << 20) /* N_ = pow2(ceil(log2(M))) */
#define M 1000000
#define N 400000
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int *yy;
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k)
if (yy[ii[j]] == yy[i_])
j++;
else if (yy[ii[j]] < yy[i_]) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
sort(ii, l, i);
l = k;
}
}
int xx1[N], xx2[N], yy1[N], yy2[N], ii1[N], ii2[N], cc[N], n, x_, y_, c, s;
int st[N_ * 2], lz[N_ * 2], pp[N_ * 2], qq[N_ * 2], ss[N_ * 2], sz[N_ * 2], mode; char ok[N_ * 2];
void pul(int i) {
if (mode == 1)
st[i] = min(st[i << 1 | 0], st[i << 1 | 1]) + lz[i];
else if (lz[i])
pp[i] = qq[i] = ss[i] = 0;
else if (i >= N_)
pp[i] = qq[i] = ss[i] = 1;
else {
int l = i << 1, r = l | 1;
pp[i] = pp[l] != sz[l] ? pp[l] : sz[l] + pp[r];
qq[i] = qq[r] != sz[r] ? qq[r] : qq[l] + sz[r];
ss[i] = max(max(ss[l], ss[r]), qq[l] + pp[r]);
}
}
void pus(int i, int x) {
lz[i] += x;
if (mode == 1)
st[i] += x;
else
pul(i);
}
void update(int l, int r, int x) {
int l_ = l += N_, r_ = r += N_;
if (l > r)
return;
for ( ; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1)
pus(l++, x);
if ((r & 1) == 0)
pus(r--, x);
}
while (l_ > 1)
pul(l_ >>= 1);
while (r_ > 1)
pul(r_ >>= 1);
}
int h1, h2;
int try(int y) {
int i;
while (h1 < n && yy1[i = ii1[h1]] - s + 1 <= y)
h1++, update(max(xx1[i] - s + 1, 0), min(xx2[i], x_ - s), cc[i]);
while (h2 < n && yy2[i = ii2[h2]] + 1 <= y)
h2++, update(max(xx1[i] - s + 1, 0), min(xx2[i], x_ - s), -cc[i]);
return st[1] <= c;
}
int check() {
int y;
memset(st, 0, N_ * 2 * sizeof *st), memset(lz, 0, N_ * 2 * sizeof *lz);
update(x_ - s + 1, N_ - 1, c + 1);
h1 = 0, h2 = 0;
if (try(0))
return 1;
while (h1 < n || h2 < n) {
if (h1 == n)
y = yy2[ii2[h2]] + 1;
else if (h2 == n)
y = yy1[ii1[h1]] - s + 1;
else
y = min(yy1[ii1[h1]] - s + 1, yy2[ii2[h2]] + 1);
if (y + s - 1 >= y_)
break;
if (try(y))
return 1;
}
return 0;
}
int main() {
int i, lower, upper;
scanf("%d%d%d%d", &x_, &y_, &c, &n);
for (i = 0; i < n; i++) {
int x1, x2, y1, y2, c;
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c), x1--, x2--, y1--, y2--;
xx1[i] = x1, xx2[i] = x2, yy1[i] = y1, yy2[i] = y2, cc[i] = c;
ii1[i] = ii2[i] = i;
}
yy = yy1, sort(ii1, 0, n);
yy = yy2, sort(ii2, 0, n);
if (c != 0) {
mode = 1;
lower = 0, upper = (x_ < y_ ? x_ : y_) + 1;
while (upper - lower > 1) {
s = (lower + upper) / 2;
if (check())
lower = s;
else
upper = s;
}
printf("%d\n", lower);
} else {
mode = 2;
for (i = N_ + N_ - 1; i >= 0; i--)
sz[i] = i >= N_ ? 1 : sz[i << 1 | 0] + sz[i << 1 | 1], pul(i);
update(x_, N_ - 1, 1);
for (lower = 0, upper = 0; upper < y_; upper++) {
while (h1 < n && yy1[i = ii1[h1]] <= upper)
h1++, update(xx1[i], xx2[i], 1);
while (ss[1] < upper - lower + 1) {
while (h2 < n && yy2[i = ii2[h2]] <= lower)
h2++, update(xx1[i], xx2[i], -1);
lower++;
}
s = max(s, upper - lower + 1);
}
printf("%d\n", s);
}
return 0;
}
Compilation message (stderr)
pyramid_base.c: In function 'main':
pyramid_base.c:121:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
121 | scanf("%d%d%d%d", &x_, &y_, &c, &n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.c:125:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
125 | scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c), x1--, x2--, y1--, y2--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |