#include <stdio.h>
#define N 1000000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
long long cross2(long long x1, long long y1, long long x2, long long y2) {
return x1 * y2 - x2 * y1;
}
long long cross2_(long long x1, long long y1, long long x2, long long y2) {
return (long long) x1 * y2 - (long long) x2 * y1;
}
int xx[N], yy[N];
long long cross(int i, int j, int k) {
return cross2(xx[j] - xx[i], yy[j] - yy[i], xx[k] - xx[i], yy[k] - yy[i]);
}
long long pp[N], qq[N];
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) {
long long c = cross2_(pp[ii[j]], qq[ii[j]], pp[i_], qq[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 main() {
static int ll[N], rr[N], qu[N], ii[N];
int n, y, i, k, cnt;
long long p, q;
scanf("%d%d", &n, &y);
for (i = 0; i < n; i++)
scanf("%d%d", &xx[i], &yy[i]);
cnt = 0;
for (i = 0; i < n; i++) {
while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
cnt--;
printf("%d\n", cnt);
ll[i] = cnt ? qu[cnt - 1] : -1;
qu[cnt++] = i;
}
cnt = 0;
for (i = n - 1; i >= 0; i--) {
while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) <= 0)
cnt--;
rr[i] = cnt ? qu[cnt - 1] : -1;
qu[cnt++] = i;
}
for (i = 2; i < n - 1; i += 2) {
pp[i] = cross2(xx[ll[i]], yy[ll[i]] - y, xx[i] - xx[ll[i]], yy[i] - yy[ll[i]]);
qq[i] = cross2(1, 0, xx[i] - xx[ll[i]], yy[i] - yy[ll[i]]);
if (qq[i] < 0)
pp[i] = -pp[i], qq[i] = -qq[i];
pp[i + 1] = cross2(xx[rr[i]], yy[rr[i]] - y, xx[i] - xx[rr[i]], yy[i] - yy[rr[i]]);
qq[i + 1] = cross2(1, 0, xx[i] - xx[rr[i]], yy[i] - yy[rr[i]]);
if (qq[i + 1] < 0)
pp[i + 1] = -pp[i + 1], qq[i + 1] = -qq[i + 1];
ii[i / 2 - 1] = i + 1;
}
sort(ii, 0, n / 2 - 1);
p = -1, q = 0, k = 0;
for (i = 0; i < n / 2 - 1; i++)
if (cross2_(p, q, pp[ii[i] - 1], qq[ii[i] - 1]) < 0)
p = pp[ii[i]], q = qq[ii[i]], k++;
printf("%d\n", k);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:54:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%d%d", &n, &y);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:56:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d%d", &xx[i], &yy[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |