将所有点极角排序,建立线段树,线段树每个节点维护该区间内所有点组成的上下凸壳。

对于一个查询,二分查找出相应区间的左右端点,在线段树上得到$O(\log n)$个节点,在相应凸壳上三分查找出与斜边叉积最大的那个点,看看是否为正即可。

时间复杂度$O(n\log^2n)$。

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010,E=2000000;
int n,m,i,c,d,ans[N],g[262150],v[E],nxt[E],ed,cnt,t0,t1;
struct P{
int x,y;
P(){}
P(int _x,int _y){x=_x,y=_y;}
P operator-(P b){return P(x-b.x,y-b.y);}
ll operator*(P b){return 1LL*x*b.y-1LL*y*b.x;}
}a[N],A,B,C,qA[N],qC[N],b[N],q0[N],q1[N];
inline bool cmp(P a,P b){return a*b>0;}
inline bool cmp0(P a,P b){return a.x==b.x?a.y>b.y:a.x<b.x;}
inline bool cmp1(P a,P b){return a.x==b.x?a.y<b.y:a.x<b.x;}
inline int getl(P x){
int l=1,r=n,mid,t=n+1;
while(l<=r)if(x*a[mid=(l+r)>>1]>0)r=(t=mid)-1;else l=mid+1;
return t;
}
inline int getr(P x){
int l=1,r=n,mid,t=0;
while(l<=r)if(x*a[mid=(l+r)>>1]<0)l=(t=mid)+1;else r=mid-1;
return t;
}
void add(int x,int a,int b){
if(c<=a&&b<=d){v[++ed]=i;nxt[ed]=g[x];g[x]=ed;return;}
int mid=(a+b)>>1;
if(c<=mid)add(x<<1,a,mid);
if(d>mid)add(x<<1|1,mid+1,b);
}
inline bool query(int x,P*q,int r){
A=qA[x],C=qC[x];
for(int l=0;l<=r;){
int len=(r-l)/3,m0=l+len,m1=r-len;
ll s0=C*(q[m0]-A),s1=C*(q[m1]-A);
if(s0>0||s1>0)return 1;
if(s0>s1)r=m1-1;else l=m0+1;
}
return 0;
}
void dfs(int x,int l,int r){
if(g[x]){
int i;
for(cnt=0,i=l;i<=r;i++)b[cnt++]=a[i];
for(sort(b,b+cnt,cmp0),q0[t0=0]=b[0],i=1;i<cnt;i++)if(b[i].x!=b[i-1].x){
while(t0&&1LL*(q0[t0].y-q0[t0-1].y)*(b[i].x-q0[t0].x)<=1LL*(b[i].y-q0[t0].y)*(q0[t0].x-q0[t0-1].x))t0--;
q0[++t0]=b[i];
}
for(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&&1LL*(q1[t1].y-q1[t1-1].y)*(b[i].x-q1[t1].x)>=1LL*(b[i].y-q1[t1].y)*(q1[t1].x-q1[t1-1].x))t1--;
q1[++t1]=b[i];
}
for(i=g[x];i;i=nxt[i]){
int j=v[i];
if(ans[j])continue;
if(query(j,q0,t0)){ans[j]=1;continue;}
if(query(j,q1,t1))ans[j]=1;
}
}
if(l==r)return;
int mid=(l+r)>>1;
dfs(x<<1,l,mid),dfs(x<<1|1,mid+1,r);
}
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
int main(){
read(n),read(m);
for(i=1;i<=n;i++)read(a[i].x),read(a[i].y);
sort(a+1,a+n+1,cmp);
for(i=1;i<=m;i++){
read(A.x),read(A.y),read(B.x),read(B.y);
if(A*B<0)swap(A,B);
qA[i]=A,qC[i]=B-A;
c=getl(A),d=getr(B);
if(c<=d)add(1,1,n);
}
dfs(1,1,n);
for(i=1;i<=m;i++)puts(ans[i]?"Y":"N");
return 0;
}

  

BZOJ1769 : [Ceoi2009]tri的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. Tri Tiling[HDU1143]

    Tri Tiling Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. TRI 解题报告

    题目大意: 在一个平面上有N(N <= 1000)个点,其中任意三点不共线,求这些点组成的三角形的面积和每和三角形内部含的点数的个数和. 数据范围: 20%的数据 N <= 50, 30% ...

  4. bzoj1767[Ceoi2009]harbingers 斜率优化dp

    1767: [Ceoi2009]harbingers Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 421  Solved: 112[Submit][S ...

  5. Tri Tiling(hdu1143)

    Tri Tiling Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. HDU2072 tri树/map/set/字符串hash

    lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数.下面你的任务是帮助xiaoou333解决这个问题 水题 就是用来试试字符串算法的 tri树 ...

  7. POJ 2663 Tri Tiling

                                                                                    Tri Tiling   Time Li ...

  8. uva 10918 - Tri Tiling(规律)

    题目链接:uva 10918 - Tri Tiling 题目大意:给出n,计算用1*2的瓷砖有多少种方法铺满3*n的地方. 解题思路:和uva 10359 - Tiling有点相似,不过难度会比较大, ...

  9. memory prefix twi,tri,trans ,tetra out 4

    1● twi 二   2● tri 三   3● trans 超过,超载   4● tetra 立体  

随机推荐

  1. [Effective JavaScript 笔记]第5章:数组和字典--个人总结

    前言 这节里其实一直都在讨论对象这个在js中的万能的数据结构.对象可以表式为多种的形式,表示为字典和数组之间的区别.更多的我觉得这章讨论多的是一些对应实现功能的相关操作,有可能出现的bug以及如何避免 ...

  2. Linux守护进程的启动方法

    导读 “守护进程”(daemon)就是一直在后台运行的进程(daemon),通常在系统启动时一同把守护进程启动起来,本文介绍如何将一个 Web 应用,启动为守护进程. 一.问题的由来 Web应用写好后 ...

  3. fastjson 的使用

    json解析:[2]fastjson 使用 http://jingyan.baidu.com/article/c74d6000672e450f6b595d53.html 利用阿里的fastjson包对 ...

  4. Linux 高可用开源方案 Keepalived VS Heartbeat对比

    1)Keepalived使用更简单:从安装.配置.使用.维护等角度上对比,Keepalived都比Heartbeat要简单得多,尤其是Heartbeat2.1.4后拆分成3个子项目,安装.配置.使用都 ...

  5. Maximum Product Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  6. 利用jQuery.validate异步验证用户名是否存在

    转:http://www.cnblogs.com/linzheng/archive/2010/10/14/1851781.html HTML头部引用: <script type="te ...

  7. Objective-C ,C++,java中常用编码格式对比

    这个题目可能不太对!主要总结一下这3种语言的不同格式 1.创建一个A类,继承B类,实现C接口(协议) 先看oc的代码 @interface A : B <C> { int a; } @pr ...

  8. Java for LeetCode 201 Bitwise AND of Numbers Range

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  9. codeforces B. Valera and Contest 解题报告

    题目链接:http://codeforces.com/problemset/problem/369/B 题目意思:给出6个整数, n, k, l, r, sall, sk ,需要找出一个满足下列条件的 ...

  10. codeforces A. Cinema Line 解题报告

    题目链接:http://codeforces.com/problemset/problem/349/A 题目意思:题目不难理解,从一开始什么钱都没有的情况下,要向每一个人售票,每张票价格是25卢布,这 ...