传送门

做法:每个卫星分别用连到左边圆与x轴交点的线的斜率和连到右边交点的线旋转90度的斜率可以表示成一个区间,问题转化成支持加/删区间和询问其中两个区间是否有交以及它们的交是否被其他区间包含。我一开始写了个O(nlog^2n)的cdq分治,判这个交的部分被包含次数是否超过2,后来dalao告诉我,直接线段树维护每个左端点对应的右端点最远在哪,每个左端点开一个堆支持删除就好了,询问的时候删掉两个区间后面再加回来,这样时间复杂度为O(nlogn)。还有为避免炸精度,直接用向量表示斜率。另外两个程序里都有许多卡常(cdq还是卡常过的),跑的飞快。

cdq:

#include<cstdio>
#include<algorithm>
using namespace std;
char B[<<],*S=B;
inline int read()
{
int x,f=;char c;
while((c=*S++)<''||c>'')if(c=='-')f=;
for(x=c-'';(c=*S++)>=''&&c<='';)x=x*+c-'';
return f?x:-x;
}
#define MN 500000
#define N 524288
struct vec
{
int x,y;
friend bool operator<(const vec&a,const vec&b){return 1LL*a.x*b.y<1LL*a.y*b.x;}
friend bool operator==(const vec&a,const vec&b){return 1LL*a.x*b.y==1LL*a.y*b.x;}
};
vec rot(const vec&a){return (vec){a.y,-a.x};}
struct work{int t,z;vec x,y;}w[MN+],q[MN+];
bool cmp(const work&a,const work&b){return a.x==b.x?a.t>b.t:a.x<b.x;}
vec l[MN+],r[MN+],c[MN+];
int cnt,ans[MN+],t[N*+],qn,sa[MN+],sb[MN+];
void add(int k,int x){for(k+=N;k;k>>=)t[k]+=x;}
int query(int l,int r)
{
int res=;
for(l+=N-,r+=N+;l^r^;l>>=,r>>=)
{
if(~l&)res+=t[l+];
if( r&)res+=t[r-];
}
return res;
}
void solve(int l,int r)
{
int mid=l+r>>,i;
if(l<r)solve(l,mid),solve(mid+,r);
if(sa[mid]==sa[l-]||sb[r]==sb[mid])return;
for(qn=,i=l;i<=mid;++i)if(w[i].t>)q[++qn]=w[i];
for(;i<=r;++i)if(!w[i].t)q[++qn]=w[i];
sort(q+,q+qn+,cmp);
for(i=;i<=qn;++i)
if(q[i].t)add(lower_bound(c+,c+cnt+,q[i].y)-c,q[i].z);
else ans[q[i].z]+=query(lower_bound(c+,c+cnt+,q[i].y)-c,cnt);
for(i=;i<=qn;++i)if(q[i].t)add(lower_bound(c+,c+cnt+,q[i].y)-c,-q[i].z);
}
int main()
{
B[fread(B,,<<,stdin)]=;
int R=read(),n=read(),i,t,x,y;
for(i=;i<=n;++i)
{
t=read();x=read();sa[i]=sa[i-];sb[i]=sb[i-];
if(t==)
{
l[++cnt]=(vec){x+R,y=read()};
c[cnt]=r[cnt]=(vec){x-R,y};
w[i]=(work){,,l[cnt],r[cnt]},++sa[i];
}
if(t==)w[i]=(work){,-,l[x],r[x]},++sa[i];
if(t==)
{
if(l[y=read()]<l[x])x^=y^=x^=y;
if(rot(r[x])<l[y])w[i]=(work){-,,,},ans[i]=;
else w[i]=(work){,i,l[y],r[x]<r[y]?r[x]:r[y]},++sb[i];
}
}
sort(c+,c+cnt+);cnt=unique(c+,c+cnt+)-c-;solve(,n);
for(i=;i<=n;++i)if(ans[i])puts(ans[i]>?"NO":"YES");
}

线段树:

#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
inline int read()
{
int x,f=;char c;
while((c=getchar())<''||c>'')if(c=='-')f=;
for(x=c-'';(c=getchar())>=''&&c<='';)x=x*+c-'';
return f?x:-x;
}
#define MN 500000
#define N 524288
#define mp(x,y) make_pair(x,y)
struct vec
{
int x,y,z;
friend bool operator<(const vec&a,const vec&b)
{return a.z||(!b.z&&1LL*a.x*b.y<1LL*a.y*b.x);}
friend bool operator==(const vec&a,const vec&b){return 1LL*a.x*b.y==1LL*a.y*b.x;}
}l[MN+],r[MN+],c[MN+],T[N*+];
priority_queue< pair<vec,int> > p[MN+];
int cnt,u[MN+],t[MN+],x[MN+],y[MN+],lp[MN+];
void change(int k,const vec&x){for(T[k+=N]=x;k>>=;)T[k]=max(T[k<<],T[k<<|]);}
vec query(int l,int r)
{
vec res=(vec){,,};
for(l+=N-,r+=N+;l^r^;l>>=,r>>=)
{
if(~l&)res=max(res,T[l+]);
if( r&)res=max(res,T[r-]);
}
return res;
}
void ins(int x)
{
int k=lp[x]?lp[x]:lp[x]=lower_bound(c+,c+cnt+,l[x])-c;
u[x]=;p[k].push(mp(r[x],x));
if(p[k].top()==mp(r[x],x))change(k,r[x]);
}
void del(int x)
{
int k=lp[x]?lp[x]:lp[x]=lower_bound(c+,c+cnt+,l[x])-c,s=;
for(u[x]=;u[p[k].top().second];++s)p[k].pop();
if(s)change(k,p[k].top().first);
}
int main()
{
int R=read(),n=read(),i,k;
for(i=;i<=n;++i)
{
t[i]=read();x[i]=read();if(t[i]!=)y[i]=read();
if(t[i]==)++cnt,c[cnt]=l[cnt]=(vec){x[i]+R,y[i],},r[cnt]=(vec){y[i],R-x[i],},x[i]=cnt;
}
sort(c+,c+cnt+);cnt=unique(c+,c+cnt+)-c-;
for(i=;i<*N;++i)T[i]=(vec){,,};
for(i=;i<=cnt;++i)p[i].push(mp(T[],));
for(i=;i<=n;++i)
{
if(t[i]==)ins(x[i]);
if(t[i]==)del(x[i]);
if(t[i]==)
{
if(l[y[i]]<l[x[i]])swap(x[i],y[i]);
if(r[x[i]]<l[y[i]]){puts("NO");continue;}
k=lp[y[i]]?lp[y[i]]:lp[y[i]]=lower_bound(c+,c+cnt+,l[y[i]])-c;
del(x[i]);del(y[i]);
puts(query(,k)<(r[x[i]]<r[y[i]]?r[x[i]]:r[y[i]])?"YES":"NO");
ins(x[i]);ins(y[i]);
}
}
}

[Codeforces]856E - Satellites的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. 敏捷冲刺(Beta版本)

    评分基准: 按时交 - 有分(计划安排-10分,敏捷冲刺-70分),检查的项目包括后文的三个个方面 冲刺计划安排(单独1篇博客,基本分5分,根据完成质量加分,原则上不超过满分10分) 七天的敏捷冲刺( ...

  2. C语言第二次作业

    一.PTA实验作业 题目1:7-1 计算分段函数[2] 1.实验代码 double x,y; scanf("%lf",&x); if (x>=0) { y=sqrt( ...

  3. Alpha阶段报告-hywteam

    一.Alpha版本测试报告 1. 在测试过程中总共发现了多少Bug?每个类别的Bug分别为多少个? BUG名 修复的BUG 不能重现的BUG 非BUG 没能力修复的BUG 下个版本修复 文件路径的表示 ...

  4. 敏捷冲刺每日报告——Day5

    1.情况简述 Alpha阶段第一次Scrum Meeting 敏捷开发起止时间 2017.10.29 00:00 -- 2017.10.30 00:00 讨论时间地点 2017.10.29晚6:00, ...

  5. 201621123060 《Java程序设计》第六周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰 ...

  6. UIImage 内存细节

    最近的一个项目,有大量的scrollView+imageView,当iPad启动较多程序,再启动自己的这个程序的时候,就爆内存退出了-- 后来把所有的生成图片的方法,全部由imageNamed改成了i ...

  7. animation & @keyframes 实现loading效果

    效果图截图如下: 直接上代码: html <!DOCTYPE html> <html> <head> <meta charset="utf-8&qu ...

  8. nyoj 孪生素数

    孪生素数问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 写一个程序,找出给出素数范围内的所有孪生素数的组数.一般来说,孪生素数就是指两个素数距离为2,近的不能再 ...

  9. GitHub 上下载单个文件夹

    写代码的一定经常去github上查看.下载一些源码,有时候会想下载一个项目中的一个文件夹里的内容,但是github上只提供了整个项目的下载,而整个项目里东西太多,压缩的文件太大,github的下载速度 ...

  10. ThreadLocal源码分析:(三)remove()方法

    在ThreadLocal的get(),set()的时候都会清除线程ThreadLocalMap里所有key为null的value. 而ThreadLocal的remove()方法会先将Entry中对k ...