[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只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- 听翁恺老师mooc笔记(9)--枚举
枚举类型的定义 用符号而不是具体的数字来表示程序中的数字,这么表示的好处是可读性,当别人看你的程序,看到的是单词,很容易理解这些数字背后的含义,那么用什么符号来表示名字哪?需要const int常量的 ...
- 学号:201621123032 《Java程序设计》第8周学习总结
1:本周学习总结 2:书面作业 2.1:ArrayList代码分析 2.1.1:解释ArrayList的contains源代码 Contains方法调用indexof方法,如果元素为null,则循环比 ...
- 关于GPUImage的导入
对于GPUImage的使用方面,GitHub上已经非常详细了,就不一一赘述了,但是对于项目的导入来说,最好的方式是 1.下载GPUImage并解压 2.打开压缩包后如图 3.打开终端,cd到此目录 4 ...
- visualVM使用jstatd和jmx连接远程jvm及遇到的问题解决
visualVM使用jstatd和jmx连接远程jvm及遇到的问题解决 JMX方式: 编辑Tomact里bin目录的catalina.sh . 在其头部加入 JAVA_OPTS=" -Dco ...
- ASCII排序
ASCII码排序 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 输入三个字符(可以重复)后,按各字符的ASCII码从小到大的顺序输出这三个字符. 输入 第一行输 ...
- ThreadLocal源码分析:(一)set(T value)方法
在ThreadLocal的get(),set()的时候都会清除线程ThreadLocalMap里所有key为null的value. 而ThreadLocal的remove()方法会先将Entry中对k ...
- php的调试工具xdebug
zend_extension = "D:/developsoftware/wamp/bin/php/php5.5.12/zend_ext/php_xdebug-2.2.5-5.5-vc11- ...
- MySQL Group Relication 部署环境入门篇
一:环境介绍 cenos 6.7 版本 数据库的版本5.7.19 二:部署规划单机多实例的部署 端口号 数据目录 group_repplicatoon 通信接口 3307 /data ...
- Bootstrap 做一个简单的母版页
随便搭的一个母版页,不太好看,只是为了看效果....请勿吐槽. 效果如图: 一.新建母版页,引入Bootstrap相关js文件 <link href="../css/bootstrap ...
- django的models模型 关联关系和关系查询
模型类关系 关系字段类型 关系型数据库的关系包括三种类型: ForeignKey:一对多,将字段定义在多的一端中. ManyToManyField:多对多,将字段定义在两端中. OneToOneFie ...