题目链接:https://vjudge.net/problem/Gym-101630A

题目大意:

  有\(n\)个操作,每次输入\(t\) \(x\) \(y\)\((t=1,2; -10^9 \le x,y \le 10^9; y > 0)\). 当\(t=1\),在坐标平面上立一个圆心在\(x,y\),半径为\(y\)的圆形靶子。当\(t=2\),往点\(x,y\)射一箭,如果在这个点上有靶子,则输出这个靶子是在第几次操作中出现的,并把这个靶子销毁;如果这个点上没有靶子,则输出\("-1"\)。

知识点:  线段树、离散化

解题思路:

  首先,肯定要离散化处理数据。然后用线段树套\(<set>\)(目的是方便删除操作)维护区间中有什么靶子。更新和删除的时候只要找到合适的区间就可以进行操作然后\(return\),不用\(push\) \(up\)或\(push\) \(down\),查询的时候则直到找到合适的靶子或者\(l==r\)为止。

AC代码:

 #include <bits/stdc++.h>

 using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
typedef long long ll;
const int maxn=2e5+; struct Input{
int t;
ll x,y;
}inp[maxn];
ll xs[maxn<<];
map<ll,int> ind;
set<int> tree[maxn<<];
void update(int L,int R,int c,int l,int r,int rt){
if(L<=l&&r<=R){
tree[rt].insert(c);
return;
}
int m=(l+r)>>;
if(L<=m) update(L,R,c,lson);
if(R>m) update(L,R,c,rson);
}
void era(int L,int R,int c,int l,int r,int rt){
if(L<=l&&r<=R){
tree[rt].erase(c);
return;
}
int m=(l+r)>>;
if(L<=m) era(L,R,c,lson);
if(R>m) era(L,R,c,rson);
}
int query(int pos,int _x,int _y,int l,int r,int rt){
if(l<=pos&&pos<=r){
set<int>::iterator it=tree[rt].begin();
for(;it!=tree[rt].end();it++){
int now=*it;
if((inp[now].x-_x)*(inp[now].x-_x)+(inp[now].y-_y)*(inp[now].y-_y)<inp[now].y*inp[now].y)
return now;
}
}
if(l==r) return -;
int m=(l+r)>>;
if(pos<=m) return query(pos,_x,_y,lson);
else return query(pos,_x,_y,rson);
}
int main(){
// freopen("in.txt","r",stdin);
int n,cnt=;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%lld%lld",&inp[i].t,&inp[i].x,&inp[i].y);
if(inp[i].t==)
xs[cnt++]=inp[i].x-inp[i].y,xs[cnt++]=inp[i].x+inp[i].y;
}
sort(xs,xs+cnt);
int m=unique(xs,xs+cnt)-xs;
for(int i=;i<m;i++){
ind[xs[i]]=i;
}
for(int i=;i<=n;i++){
if(inp[i].t==)
update(ind[inp[i].x-inp[i].y]+,ind[inp[i].x+inp[i].y],i,,m-,);
else{
int pos=-;
int l=,r=m-;
while(l<=r){
int mid=(l+r)>>;
if(xs[mid-]>inp[i].x) r=mid-;
else if(xs[mid]<inp[i].x) l=mid+;
else{
pos=mid;
break;
}
}
if(pos==-) printf("-1\n");
else{
int ret=query(pos,inp[i].x,inp[i].y,,m-,);
if(ret==-)
printf("-1\n");
else{
printf("%d\n",ret);
era(ind[inp[ret].x-inp[ret].y]+,ind[inp[ret].x+inp[ret].y],ret,,m-,);
}
}
}
}
return ;
}

Gym101630A Archery Tournament的更多相关文章

  1. 2017-2018 ACM-ICPC Northern Eurasia(A.Archery Tournament)

    题目链接:https://vjudge.net/problem/Gym-101630A 题意: n个事件,t=1 代表增加一个圆心为(x,y),半径为 abs(y)的靶子,t=2,代表射击的坐标为(x ...

  2. A - Archery Tournament 动态开点+vecotor 神仙题

    存图还是像矩形一样的存,每个节点存所在区级内部的圆的编号,然后暴力判断,开始我也有这个想法,但是...这TM也能过...仔细想想,貌似好像是可以过,时间复杂度玄学无法证明.... #include&l ...

  3. NEERC-2017

    A. Archery Tournament 用线段树套set维护横坐标区间内的所有圆,查询时在$O(\log n)$个set中二分查找即可. 时间复杂度$O(n\log^2n)$. #include& ...

  4. 【做题】neerc2017的A、C、I、L

    A - Archery Tournament 一开始往化简公式的方向去想,结果没什么用. 考虑与一条垂线相交的圆的个数.不难YY,当圆的个数最多时,大概就是这个样子的: 我们稍微推一下式子,然后就能发 ...

  5. 2017 NEERC

    2017 NEERC Problem A. Archery Tournament 题目描述:在二维平面上,会陆续出现一些圆,以及一些询问,询问点是否在圆内,如果是,则输出那个圆,并把那个圆删掉,否则输 ...

  6. 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) 日常训练

    A - Archery Tournament 题目大意:按时间顺序出现靶子和射击一个位置,靶子的圆心为(x, y)半径为r,即圆与x轴相切,靶子不会重叠,靶子被击中后消失, 每次射击找出哪个靶子被射中 ...

  7. Codeforces CF#628 Education 8 A. Tennis Tournament

    A. Tennis Tournament time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Rock-Paper-Scissors Tournament[HDU1148]

    Rock-Paper-Scissors TournamentTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  9. CF 628A --- Tennis Tournament --- 水题

    CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...

随机推荐

  1. 第八章服务器raid及配置实战

      版本 特点 磁盘个数 可用空间 故障磁盘数 应用环境 RAID0 读写速度快,数据容易丢失 两个 全部 一块 测试,临时性 RAID1 读写速度慢,数据可靠 至少两个,可以2的倍数 总容量的一半 ...

  2. 虚拟机 VMware Workstation Pro 15.5.0 及永久激活密钥

    虚拟机 VMware Workstation Pro 15.5.0 及永久激活密钥 虚拟机下载地址:https://download3.vmware.com/software/wkst/file/VM ...

  3. Vue Cli 报错:You are using the runtime-only build of Vue where the template compiler is not availabl

    报错原因: 这里引用的是vue.runtime.esm.js,造成的不能正常运行. vue-cli 2.x 解决方法: 在webpack.base.conf.js配置文件中多加了一段代码,将 vue/ ...

  4. #Week8 Advice for applying ML & ML System Design

    一.Evaluating a Learning Algorithm 训练后测试时如果发现模型表现很差,可以有很多种方法去更改: 用更多的训练样本: 减少/增加特征数目: 尝试多项式特征: 增大/减小正 ...

  5. Java_Web--JDBC 增加记录操作模板

    如果不能成功链接数据库,我的博客JAVA中有详细的介绍,可以看一下 import java.sql.Connection; import java.sql.DriverManager; import ...

  6. 初学dp心得

    从STL到贪心,再到现在的动态规划,可以说动态规划真的让我学的有点蒙,对于一些题目,会做,但是不会用DP,现在还不能熟练的写出状态转移方程,更重要的是,自己宛如一个哺乳期的小孩,做题需要套模板,没有模 ...

  7. Programming Languages_04 Deferred Substitution

    Deferred Substitution 在执行出现with时,利用"substitution",每次with的出现,它都绕着整个body置换.这一方式是由F1WAE到env再到 ...

  8. 网络流 I - Fox And Dinner CodeForces - 510E

    Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). T ...

  9. LeetCode--LinkedList--83.Remove Duplicates from Sorted List(Easy)

    题目地址https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 83. Remove Duplicates from Sor ...

  10. STM32 使用IQmath实现SVPWM

    IQMATH TI的片子很香,做的也很好,但是成本相对ST会更高,电机控制方面,TI无疑是做的最好的方案之一,另外TI针对没有浮点运算器的定点DSP推出了IQMATH库,在使用Q格式对数据进行分析和处 ...