bzoj2961【cdq分治】

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
typedef long long LL;
inline int read()
{
    int x=0;bool f=0;char c=getchar();
    for (;c<'0'||c>'9';c=getchar()) f=c=='-'?1:0;
    for (;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
    return f?-x:x;
}
const int N=500010;
const double eps=1e-6;
int top,num,l[32],r1[32],r2[32];
bool no;
double A,B,C;
struct na
{
    double x,y;
}ins[N],newq[N],q1[N],q2[N];
 
inline bool cmp1 (const na &a,const na &b)
{
    if (a.x!=b.x) return a.x<b.x;
    return a.y>b.y;
}
 
inline bool cmp2(const na &a,const na &b)
{
    if (a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}
 
inline double cross(const na &a,const na &b,const na &c)
{
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
 
inline double cal(const na &a) {return A*a.x+B*a.y;}
 
void rebuild()
{
    while (num&&top-l[num]==l[num]-l[num-1]) num--;l[++num]=top;
    int cnt=0;
    for (int i=l[num-1]+1;i<=top;i++) newq[++cnt]=ins[i];
    int L=l[num-1]+1,R=L-1;sort(newq+1,newq+cnt+1,cmp1);
    for (int i=1;i<=cnt;i++)
    {
        while (R>L&&cross(q1[R-1],q1[R],newq[i])>-eps) R--;
        q1[++R]=newq[i];
    }
    r1[num]=R;R=L-1;sort(newq+1,newq+cnt+1,cmp2);
    for (int i=1;i<=cnt;i++)
    {
        while (R>L&&cross(q2[R-1],q2[R],newq[i])<eps) R--;
        q2[++R]=newq[i];
    }
    r2[num]=R;
}
 
bool query(int l,int r,na *q)
{
    int m1,m2;double s1,s2;
    while (l<=r)
    {
        m1=l+(r-l)/3;m2=l+r-m1;s1=cal(q[m1]);s2=cal(q[m2]);
        if (s1<s2) {if (s1<C) return no=1;r=m2-1;}
        else {if (s2<C) return no=1;l=m1+1;}
    }
    return 0;
}
 
int main()
{
    for (int cas=read(),op;cas--;)
    {
        op=read();scanf("%lf%lf",&A,&B);
        if (!op) ins[++top]=(na){A,B},rebuild();
        else
        {
            if (!top) {puts("No");continue;}
            C=A*A+B*B;A*=2;B*=2;no=0;
            for (int i=1;i<=num;i++)
            {
                if (B<0) query(l[i-1]+1,r1[i],q1);
                else query(l[i-1]+1,r2[i],q2);
                if (no) break;
            }
            puts(no?"No":"Yes");
        }
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章