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>
#define N 1000000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int ll[N], rr[N], hh[N];
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = ll[hh[j]] != ll[h] ? ll[hh[j]] - ll[h] : rr[h] - rr[hh[j]];
if (c == 0)
j++;
else if (c < 0) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
}
sort(hh, l, i);
l = k;
}
}
int main() {
static int xx[N], yy[N];
int n, m, h, h_, h1, i, j, tmp, x, y;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &xx[i], &yy[i]);
i = -1;
for (j = 0; j < n; j++)
if ((yy[j] < 0) != (yy[(j + 1) % n] < 0))
i = j;
m = 0;
for (j = 0; j < n; j++)
if ((yy[j] < 0) != (yy[(j + 1) % n] < 0)) {
if (yy[j] > 0) {
ll[m] = xx[i], rr[m] = xx[j];
if (ll[m] > rr[m])
tmp = ll[m], ll[m] = rr[m], rr[m] = tmp;
m++;
}
i = j;
}
for (h = 0; h < m; h++)
hh[h] = h;
sort(hh, 0, m);
x = 0;
for (h = 0, h1 = -1; h < m; h++) {
h_ = hh[h];
if (h1 == -1 || rr[h1] < rr[h_])
h1 = h_, x++;
}
y = 0;
for (h = m - 1, h1 = -1; h >= 0; h--) {
h_ = hh[h];
if (h1 == -1 || rr[h1] > rr[h_])
h1 = h_, y++;
}
printf("%d %d\n", x, y);
return 0;
}
Compilation message (stderr)
cut.cpp: In function 'int main()':
cut.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
cut.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | 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... |