이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 200000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N * 2], yy[N * 2], lr[N * 2];
int compare_y(int i, int j) {
return yy[i] - yy[j];
}
int compare_xy(int i, int j) {
return xx[i] != xx[j] ? xx[i] - xx[j] : yy[i] - yy[j];
}
int compare_lr(int i, int j) {
return lr[i] - lr[j];
}
int (*compare)(int, int);
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) {
int c = compare(ii[j], i_);
if (c == 0)
j++;
else if (c < 0) {
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 iq[N + 1], pq[N], cnt;
int lt(int i, int j) { return lr[i << 1 | 1] > lr[j << 1 | 1]; }
int p2(int p) {
return (p *= 2) > cnt ? 0 : (p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p);
}
void pq_up(int i) {
int p, q, j;
for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q)
iq[pq[j] = p] = j;
iq[pq[i] = p] = i;
}
void pq_dn(int i) {
int p, q, j;
for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q)
iq[pq[j] = p] = j;
iq[pq[i] = p] = i;
}
void pq_add(int i) {
pq[i] = ++cnt, pq_up(i);
}
int pq_remove_first() {
int i = iq[1], j = iq[cnt--];
if (j != i)
pq[j] = 1, pq_dn(j);
pq[i] = 0;
return i;
}
void pq_remove(int i) {
int j = iq[cnt--];
if (j != i)
pq[j] = pq[i], pq_up(j), pq_dn(j);
pq[i] = 0;
}
int main() {
static int ii[N * 2], hh[N * 2], cc[N * 2], qu[N];
int n, m, h, h_, i, j, c, ans;
scanf("%d", &n);
for (i = 0; i < n * 2; i++) {
scanf("%d%d", &xx[i], &yy[i]);
yy[i] = yy[i] << 1 | (i < n ? 0 : 1);
}
for (i = 0; i < n * 2; i++)
ii[i] = i;
compare = compare_y, sort(ii, 0, n * 2);
for (i = 0; i < n * 2; i++)
yy[ii[i]] = i;
c = 0;
for (i = 0; i < n * 2; i++) {
if (ii[i] < n)
c++;
else
c--;
cc[i] = c;
}
compare = compare_xy, sort(ii, 0, n * 2);
m = 0;
for (i = 0; i < n * 2; i = j) {
j = i;
cnt = 0;
while (j < n * 2 && xx[ii[j]] == xx[ii[i]]) {
if (ii[j] < n)
qu[cnt++] = j;
else if (cnt)
lr[m << 1 | 0] = yy[ii[qu[--cnt]]], lr[m << 1 | 1] = yy[ii[j]], m++;
j++;
}
}
for (h = 0; h < m * 2; h++)
hh[h] = h;
compare = compare_lr, sort(hh, 0, m * 2);
ans = n, cnt = 0;
for (i = 0, h = 0; i < n * 2; i++) {
while (h < m * 2 && lr[hh[h]] == i) {
h_ = hh[h++];
if ((h_ & 1) == 0)
pq_add(h_ >> 1);
else if (pq[h_ >> 1])
pq_remove(h_ >> 1), ans--;
}
while (cnt > cc[i])
pq_remove_first();
}
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
worst_reporter2.c: In function 'main':
worst_reporter2.c:98:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
worst_reporter2.c:100:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | scanf("%d%d", &xx[i], &yy[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |