## Description

$1\leq n\leq 50000,1\leq t\leq 50$

## Code

#include <bits/stdc++.h>
#define pii pair<long long, long long>
#define fr first
#define sc second
#define a(i) (b[i].fr)
#define p(i) (b[i].sc)
using namespace std;
const int N = 50000+5;

int t, n, tot, kp[N], vis[N];
pii a[N], b[N];
int q[N], top, ANS;

int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n); tot = 0;
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &a[i].sc, &a[i].fr);
sort(a+1, a+n+1); a[n+1].fr = -1;
for (int i = 1; i <= n; i++)
if (a[i].fr != a[i+1].fr) {
if (a[i].fr != a[i-1].fr || a[i].sc != a[i-1].sc) {
b[++tot] = a[i], vis[tot] = 1;

}
else if (a[i].fr == a[i-1].fr && a[i].sc == a[i-1].sc) b[++tot] = a[i], vis[tot] = 0;
}
n = tot; b[0].fr = b[1].fr-1, b[0].sc = -2147483647;
top = 0;
for (int i = 1; i <= n; i++) {
int l = 1, r = top, ans = 0, m, j, k;
while (l <= r) {
m = (l+r)>>1, j = q[m], k = q[m-1];
if (1ll*(p(i)-p(j))*(a(j)-a(k)) < 1ll*(p(j)-p(k))*(a(i)-a(j))) ans = m, l = m+1;
else r = m-1;
}
kp[i] = q[ans];
while (top && 1ll*(p(i)-p(q[top]))*(a(q[top])-a(q[top-1])) >= 1ll*(p(q[top])-p(q[top-1]))*(a(i)-a(q[top]))) --top;
q[++top] = i;
}
if (n) ANS = vis[n];
else ANS = 0;
b[0].fr = 1ll+b[n].fr;
q[top = 1] = n;
for (int i = n-1; i >= 1; i--) {
int l = 1, r = top, ans = top, m, j, k;
while (l <= r) {
m = (l+r)>>1, j = q[m], k = q[m-1];
if (1ll*(p(i)-p(j))*(a(j)-a(k)) > 1ll*(p(j)-p(k))*(a(i)-a(j))) ans = m, l = m+1;
else r = m-1;
}
int x = kp[i], y = q[ans];
if (p(i) > p(y) && 1ll*(p(i)-p(x))*(a(y)-a(i)) > 1ll*(p(i)-p(y))*(a(x)-a(i))) ANS += vis[i];
while (top && 1ll*(p(i)-p(q[top]))*(a(q[top])-a(q[top-1])) <= 1ll*(p(q[top])-p(q[top-1]))*(a(i)-a(q[top]))) --top;
q[++top] = i;
}
printf("%d\n", ANS);
}
return 0;
}
posted @ 2020-08-08 00:18  NaVi_Awson  阅读(130)  评论(0编辑  收藏  举报