[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只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- Beta版本展示
Beta版本展示 开发团队:MyGod 团队成员:程环宇 张芷祎 王田路 张宇光 王婷婷 源码地址:https://github.com/WHUSE2017/MyGod MyGod团队项目的目标: 让 ...
- Beta冲刺NO.1
Beta冲刺 第一天 1. 昨天的困难 由于今天还是第一天,所以暂时没有昨天的困难. 2. 今天解决的进度 潘伟靖: 对代码进行了review 1.将某些硬编码改为软编码 2.合并了一些方法,简化代码 ...
- Winserver+Apache+django部署
废话不多说,干活直接上. winserver2012 + django2.0.1 + apache 部署过程 python ==> 3.4 64位 https://www.python.org/ ...
- php的借用其他网站的页面覆盖Logo的技巧
php的借用其他网站的页面覆盖Logo的技巧, <body> <div id="red_f"></div> <div class=&quo ...
- 什么是KMP算法?KMP算法推导
花了大概3天时间,了解,理解,推理KMP算法,这里做一次总结!希望能给看到的人带来帮助!! 1.什么是KMP算法? 在主串Str中查找模式串Pattern的方法中,有一种方式叫KMP算法 KMP算法是 ...
- 机器学习中的K-means算法的python实现
<机器学习实战>kMeans算法(K均值聚类算法) 机器学习中有两类的大问题,一个是分类,一个是聚类.分类是根据一些给定的已知类别标号的样本,训练某种学习机器,使它能够对未知类别的样本进行 ...
- Mego开发文档 - 快速开始
Mego 快速开始 我们将创建一个简单的数据新增及查询来演示 Mego 的使用过程.演示中都是使用 Visual Studio 2017 作为开发工具,SQL Server 2012 作为数据库. 创 ...
- HTTP协议扫盲(一)HTTP协议的基本概念和通讯原理
一.HTTP协议的概念 1.引子 - 从url开始 URL(Uniform Resource Locator) 地址用于描述一个网络上的资源, 基本格式如下 schema://host[:port# ...
- oracle中求1到100之间的质数和
declare i number:=1; j number:=0; sum1 number:=0;begin while(i<100) loop i:=i+1; j:=2; while(mod( ...
- SpringBoot框架中JPA使用的一些问题
主要是自己在使用JPA框架时遇到的一个坑,拿出来分享一下 首先上一个简单JPA框架实体 public interface EnterpriseInfoDao extends JpaSpecificat ...