#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;
}
Compilation message
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]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
240 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
240 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
596 KB |
Output is correct |
24 |
Correct |
5 ms |
596 KB |
Output is correct |
25 |
Correct |
6 ms |
564 KB |
Output is correct |
26 |
Correct |
6 ms |
596 KB |
Output is correct |
27 |
Correct |
5 ms |
596 KB |
Output is correct |
28 |
Correct |
6 ms |
572 KB |
Output is correct |
29 |
Correct |
6 ms |
656 KB |
Output is correct |
30 |
Correct |
6 ms |
564 KB |
Output is correct |
31 |
Correct |
6 ms |
684 KB |
Output is correct |
32 |
Correct |
7 ms |
596 KB |
Output is correct |
33 |
Correct |
6 ms |
568 KB |
Output is correct |
34 |
Correct |
6 ms |
688 KB |
Output is correct |
35 |
Correct |
6 ms |
596 KB |
Output is correct |
36 |
Correct |
5 ms |
596 KB |
Output is correct |
37 |
Correct |
6 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
240 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
596 KB |
Output is correct |
24 |
Correct |
5 ms |
596 KB |
Output is correct |
25 |
Correct |
6 ms |
564 KB |
Output is correct |
26 |
Correct |
6 ms |
596 KB |
Output is correct |
27 |
Correct |
5 ms |
596 KB |
Output is correct |
28 |
Correct |
6 ms |
572 KB |
Output is correct |
29 |
Correct |
6 ms |
656 KB |
Output is correct |
30 |
Correct |
6 ms |
564 KB |
Output is correct |
31 |
Correct |
6 ms |
684 KB |
Output is correct |
32 |
Correct |
7 ms |
596 KB |
Output is correct |
33 |
Correct |
6 ms |
568 KB |
Output is correct |
34 |
Correct |
6 ms |
688 KB |
Output is correct |
35 |
Correct |
6 ms |
596 KB |
Output is correct |
36 |
Correct |
5 ms |
596 KB |
Output is correct |
37 |
Correct |
6 ms |
652 KB |
Output is correct |
38 |
Correct |
250 ms |
14100 KB |
Output is correct |
39 |
Correct |
239 ms |
12944 KB |
Output is correct |
40 |
Correct |
245 ms |
12888 KB |
Output is correct |
41 |
Correct |
229 ms |
12980 KB |
Output is correct |
42 |
Correct |
266 ms |
13704 KB |
Output is correct |
43 |
Correct |
266 ms |
14336 KB |
Output is correct |
44 |
Correct |
283 ms |
14440 KB |
Output is correct |
45 |
Correct |
271 ms |
14404 KB |
Output is correct |
46 |
Correct |
260 ms |
14320 KB |
Output is correct |
47 |
Correct |
280 ms |
16348 KB |
Output is correct |
48 |
Correct |
273 ms |
14104 KB |
Output is correct |
49 |
Correct |
270 ms |
14220 KB |
Output is correct |
50 |
Correct |
268 ms |
14188 KB |
Output is correct |
51 |
Correct |
259 ms |
14200 KB |
Output is correct |
52 |
Correct |
262 ms |
14840 KB |
Output is correct |