BZOJ3941 : [Usaco2015 Feb]Fencing the Herd
若所有点同侧则表明将各个点带入直线解析式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的更多相关文章
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈
[BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...
- 3942: [Usaco2015 Feb]Censoring [KMP]
3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 375 Solved: 206[Subm ...
- Bzoj3943 [Usaco2015 Feb]SuperBull
3943: [Usaco2015 Feb]SuperBull Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 300 Solved: 185 Desc ...
- bzoj3940: [Usaco2015 Feb]Censoring
AC自动机.为什么洛谷水题赛会出现这种题然而并不会那么题意就不说啦 .终于会写AC自动机判断是否是子串啦...用到kmp的就可以用AC自动机水过去啦 #include<cstdio> #i ...
- BZOJ_3940_[Usaco2015 Feb]Censoring_AC自动机
BZOJ_3940_[Usaco2015 Feb]Censoring_AC自动机 Description FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S.他有一个包含n个 ...
- BZOJ_3942_[Usaco2015 Feb]Censoring_KMP
BZOJ_3942_[Usaco2015 Feb]Censoring_KMP Description 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一 ...
- 3942: [Usaco2015 Feb]Censoring
3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MB Submit: 964 Solved: 480 [Subm ...
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
随机推荐
- ZeroMQ之Publish/Subscribe (Java)
前面的文章介绍了比较简单的Request/Subscribe模式, 这篇文章介绍更为经典的Publish/Subscribe通信模式用来ZeroMQ的实现,其通信方式如下图: 客户端(subscrib ...
- PHP快速抓取快递信息
<?php header("Content-type:text/html;charset=utf-8"); /** * Express.class.php 快递查询类 * @ ...
- Linux_DHCP服务搭建
Linux网络参数的设置 1. 修改主机名 # vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=bj.com 2. 修 ...
- cobbler部署机器的默认密码
修改cobbler的默认密码: 用 openssl 生成一串密码后加入到 cobbler 的配置文件(/etc/cobbler/settings)里,替换 default_password_crypt ...
- 深入了解PooledConnectionFactory CachingConnectionFactory Sin
深入理解PooledConnectionFactory CachingConnectionFactory SingleConnectionFactory PooledConnectionFactory ...
- 《ASP.NET MVC4 WEB编程》学习笔记------Web API
本文截取自情缘 1. Web API简单说明 近来很多大型的平台都公开了Web API.比如百度地图 Web API,做过地图相关的人都熟悉.公开服务这种方式可以使它易于与各种各样的设备和客户端平台集 ...
- IE8 不支持html5 placeholder的解决方案
IE8不支持html5 placeholder的解决方法. /** * jQuery EnPlaceholder plug * version 1.0 2014.07.01戈志刚 * by Frans ...
- Java for LeetCode 026 Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- DisJSet:Find them, Catch them(POJ 1703)
抓住他们! 题目大意:两个黑社会帮派,互相打架,现在你很多条信息,要你确定两个人是否属于不同帮派 这题很有趣,题目不是直接给你两个人是否是一个帮派的,他给你的是不同帮派的,也就是给你很多个不同的要你找 ...
- HDU 1023 Traning Problem (2) 高精度卡特兰数
Train Problem II Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Sub ...