若所有点同侧则表明将各个点带入直线解析式ax+by-c后得到的值均同号
等价于最大值和最小值同号
考虑CDQ分治,每一步分治的过程中求出上下凸壳,然后三分答案即可
时间复杂度$O(n\log^2n)$

#include<cstdio>
#include<algorithm>
typedef long long ll;
const int N=200010;
const ll inf=1LL<<60;
struct P{int x,y;P(){}P(int _x,int _y){x=_x,y=_y;}}b[N],q1[N],q2[N],now;
struct Q{int a,b,q;ll c;Q(){}Q(int _a,int _b,ll _c,int _q){a=_a,b=_b,c=_c,q=_q;}}a[N];
int n,m,i,op,A,B,cnt,t1,t2,m1,m2,len;ll C,s1,s2,ans1[N],ans2[N];
inline bool cmp1(P a,P b){return a.x==b.x?a.y>b.y:a.x<b.x;}
inline bool cmp2(P a,P b){return a.x==b.x?a.y<b.y:a.x<b.x;}
inline ll mul(P b){return(ll)now.x*b.x+(ll)now.y*b.y;}
inline void Max(ll&a,ll b){if(a<b)a=b;}
inline void Min(ll&a,ll b){if(a>b)a=b;}
inline void read(int&a){
char c;bool f=0;a=0;
while(!((((c=getchar())>='0')&&(c<='9'))||(c=='-')));
if(c!='-')a=c-'0';else f=1;
while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';
if(f)a=-a;
}
inline void read(ll&a){
char c;bool f=0;a=0;
while(!((((c=getchar())>='0')&&(c<='9'))||(c=='-')));
if(c!='-')a=c-'0';else f=1;
while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';
if(f)a=-a;
}
inline void askmax1(ll&t){
for(int l=0,r=t1;l<=r&&t<C;){
len=(r-l)/3;
if((s1=mul(q1[m1=l+len]))>(s2=mul(q1[m2=r-len])))Max(t,s1),r=m2-1;else Max(t,s2),l=m1+1;
}
}
inline void askmax2(ll&t){
for(int l=0,r=t2;l<=r&&t<C;){
len=(r-l)/3;
if((s1=mul(q2[m1=l+len]))>(s2=mul(q2[m2=r-len])))Max(t,s1),r=m2-1;else Max(t,s2),l=m1+1;
}
}
inline void askmin1(ll&t){
for(int l=0,r=t1;l<=r&&t>C;){
len=(r-l)/3;
if((s1=mul(q1[m1=l+len]))<(s2=mul(q1[m2=r-len])))Min(t,s1),r=m2-1;else Min(t,s2),l=m1+1;
}
}
inline void askmin2(ll&t){
for(int l=0,r=t2;l<=r&&t>C;){
len=(r-l)/3;
if((s1=mul(q2[m1=l+len]))<(s2=mul(q2[m2=r-len])))Min(t,s1),r=m2-1;else Min(t,s2),l=m1+1;
}
}
void solve(int l,int r){
if(l==r)return;
int mid=(l+r)>>1;
solve(l,mid),solve(mid+1,r);
for(cnt=0,i=l;i<=mid;i++)if(!a[i].q)b[cnt++]=P(a[i].a,a[i].b);
if(!cnt)return;
for(std::sort(b,b+cnt,cmp1),q1[t1=0]=b[0],i=1;i<cnt;i++)if(b[i].x!=b[i-1].x){
while(t1&&(ll)(q1[t1].y-q1[t1-1].y)*(b[i].x-q1[t1].x)<=(ll)(b[i].y-q1[t1].y)*(q1[t1].x-q1[t1-1].x))t1--;
q1[++t1]=b[i];
}
for(std::sort(b,b+cnt,cmp2),q2[t2=0]=b[0],i=1;i<cnt;i++)if(b[i].x!=b[i-1].x){
while(t2&&(ll)(q2[t2].y-q2[t2-1].y)*(b[i].x-q2[t2].x)>=(ll)(b[i].y-q2[t2].y)*(q2[t2].x-q2[t2-1].x))t2--;
q2[++t2]=b[i];
}
for(i=r;i>mid;i--)if(a[i].q){
now=P(a[i].a,a[i].b),C=a[i].c;
if(a[i].b>0)askmin2(ans1[i]),askmax1(ans2[i]);else askmin1(ans1[i]),askmax2(ans2[i]);
}
}
int main(){
read(n),read(m);
for(i=1;i<=n;i++)read(A),read(B),a[i]=Q(A,B,0,0);
for(i=1;i<=m;i++){
read(op),read(A),read(B);
if(op==1)a[n+i]=Q(A,B,0,0);else read(C),a[n+i]=Q(A,B,C,1);
ans1[n+i]=inf,ans2[n+i]=-inf;
}
solve(1,n+=m);
for(i=1;i<=n;i++)if(a[i].q)puts(ans2[i]<a[i].c||ans1[i]>a[i].c?"YES":"NO");
return 0;
}

  

BZOJ3941 : [Usaco2015 Feb]Fencing the Herd的更多相关文章

  1. 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树

    [BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...

  2. 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈

    [BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...

  3. 3942: [Usaco2015 Feb]Censoring [KMP]

    3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 375  Solved: 206[Subm ...

  4. Bzoj3943 [Usaco2015 Feb]SuperBull

    3943: [Usaco2015 Feb]SuperBull Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 300  Solved: 185 Desc ...

  5. bzoj3940: [Usaco2015 Feb]Censoring

    AC自动机.为什么洛谷水题赛会出现这种题然而并不会那么题意就不说啦 .终于会写AC自动机判断是否是子串啦...用到kmp的就可以用AC自动机水过去啦 #include<cstdio> #i ...

  6. BZOJ_3940_[Usaco2015 Feb]Censoring_AC自动机

    BZOJ_3940_[Usaco2015 Feb]Censoring_AC自动机 Description FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S.他有一个包含n个 ...

  7. BZOJ_3942_[Usaco2015 Feb]Censoring_KMP

    BZOJ_3942_[Usaco2015 Feb]Censoring_KMP Description 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一 ...

  8. 3942: [Usaco2015 Feb]Censoring

    3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MB Submit: 964 Solved: 480 [Subm ...

  9. 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树

    [BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...

随机推荐

  1. characterCustomezition的资源打包代码分析

    using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; class Creat ...

  2. ssh和mvc理论基础

    ssh中mvc到底指的什么 mvcsshhibernatespringstrutsioc在SSH整合的架构中,Spring充当了一个容器的作用,Spring使用IOC和AOP技术接管了Hibernat ...

  3. node.js+websocket实现简易聊天室

    (文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) websocket提供了一种全双工客户端服务器的异步通信方法,这种通信方法使用ws或者wss协议,可 ...

  4. (转)搞ACM的你伤不起

    劳资六年前开始搞ACM啊!!!!!!!!!! 从此踏上了尼玛不归路啊!!!!!!!!!!!! 谁特么跟劳资讲算法是程序设计的核心啊!!!!!! 尼玛除了面试题就没见过用算法的地方啊!!!!!! 谁再跟 ...

  5. devstack重启后不能运行

    devstack 重启后没有运行服务. 解释: “Note if you reboot your machine running devstack, you need to rerun stack.s ...

  6. Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...

  7. 4.在二元树中找出和为某一值的所有路径[FindPathsInBinaryTree]

    [题目]: 输入一个整数和一棵二元树.从树的根结点开始往下访问一直到叶结点所经过的所有结点形成一条路径.打印出和与输入整数相等的所有路径. 例如输入整数22和如下二元树 10              ...

  8. Android Fragment间对象传递

    由于Activity相对较为笨重,因而在日常的开发中很多时候会用到Fragment.然而Activity之间是通过Intent进行数据的传递,那Fragment是通过什么来进行传递的呢?Fragmen ...

  9. HDU 2.1.7 (求定积分公式)

    The area Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  10. Linux vim 底下显示行号

    使用 vim /etc/vimrc 然后进入之后再 set ruler" show the cursor position all the time 底下再加上 set nu 保存退出 :w ...