[Codeforces]856E - Satellites
做法:每个卫星分别用连到左边圆与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的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- alpha-咸鱼冲刺day9-紫仪
总汇链接 一,合照 emmmmm.自然还是没有的. 二,项目燃尽图 三,项目进展 大概差不多了.不过提交似乎又出了问题正在修改ing 四,问题困难 页面整合啥的凑合一下.因为后面跟着学长速成的PH ...
- Alpha冲刺No.9
一.站立式会议 继续解决真实手机中的问题,如果不能解决,请教助教学姐 数据库备忘录的获取和上传 细化界面设计 二.项目实际进展 用一种奇怪的方式解决了真实手机中的问题,在总结里细说. 完成数据库备忘录 ...
- c语言第一次作业——输入与输出格式
一.PTA实验作业 1.温度转换 本题要求编写程序,计算华氏温度150°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代码 ...
- 201621123050 《Java程序设计》第13周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 为你的系统增加网络功能(购物车.图书馆管理.斗地主等)-分组完成 为了让你的系统可以被多个用户通过网 ...
- 201621123050 《Java程序设计》第1周学习总结
1.本周学习总结 java历史概述 java特点:1.简单 2.面向对象 3.健壮 4.跨平台 5.类库众多 JDK.JRE.JVM JDK:JAVA 开发工具包 ,包含JRE JRE: JAVA运行 ...
- Archlinux下i3wm与urxvt的配置
前段时间学习了GitHub的两位前辈:Airblader和wlh320.他们的相关教程在https://github.com/Airblader/i3和https://github.com/wlh32 ...
- 用greenlet实现Python中的并发
from greenlet import greenlet def test1(): print 12 gr2.switch() print 34 def test2(): print 56 gr1. ...
- Flask jinja2 全局函数,宏
内置全局函数 dict()函数,方便生成字典型变量 {% set user = dict(name='Mike',age=15) %} <p>{{ user | tojson | safe ...
- python 关键字的操作
声明:本文章默认使用的是python 3.6.1 1.要想当个牛逼的程序员,就要精通各种hello world的写法,当然,我不牛逼,只能用python去写^..^! print("Hell ...
- php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中
php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中 1.phalcon框架的安装: phalcon框架在windows本地安装可以利用wamp软件,安装之后可以查看对应 ...