Codeforces Beta Round #19D. Points
来源:互联网 发布:2017网络虚假新闻案例 编辑:程序博客网 时间:2024/06/08 04:38
链接:http://www.codeforces.com/contest/19/problem/D
题意:给定n个操作,add x y:在平面坐标系中[x,y]位置插入一个点,remove x y:将平面中[x,y]位置的点删掉,find x y:输出所有[x',y'],x'>x,y'>y中x'最小的那个点,如果有多个点输出y'最小的那个点。
分析:我们先离线将所有插入点和询问点都处理出来,将它们以x为第一关键字y为第二关键字从小到大排序。如果插入点的话,我们就找到这个点对应的位置标记有该点,查询的话我们只需要在大于x的范围中找y'>y的最小位置即可。比如我们现在查询[x,y],那么我们只需要在排好序的数字中找到第一个大于x的位置开始,找到第一个y'>y的位置即可。这里找最左边的y'直接用线段树维护一下即可。O(nlogn)。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=200010;const int MAX=1000000100;const int mod=100000000;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=998244353;const int INF=1000000010;typedef double db;typedef unsigned long long ull;struct node { int op,x,y; node() {} node(int op,int x,int y):op(op),x(x),y(y) {} bool operator < (const node a) const { if (x!=a.x) return x<a.x; return y<a.y; }}ope[N],add[N];char s[5];int k,sum[4*N],mx[4*N];void build(int x,int l,int r) { sum[x]=mx[x]=0; if (l==r) return ; int mid=(l+r)>>1; build(2*x,l,mid); build(2*x+1,mid+1,r);}int find_point(int x,int y) { int l=0,r=k,mid=k>>1;; while (l+1<r) if (add[mid].x>x||(add[mid].x==x&&add[mid].y>=y)) { r=mid;mid=(l+r)>>1; } else { l=mid;mid=(l+r)>>1; } return r;}void add_point(int x,int l,int r,int w,int z) { if (l==r) { mx[x]=z;return ; } int mid=(l+r)>>1; if (w<=mid) add_point(2*x,l,mid,w,z); else add_point(2*x+1,mid+1,r,w,z); mx[x]=max(mx[2*x],mx[2*x+1]);}void del_point(int x,int l,int r,int w) { if (l==r) { mx[x]=0;return ; } int mid=(l+r)>>1; if (w<=mid) del_point(2*x,l,mid,w); else del_point(2*x+1,mid+1,r,w); mx[x]=max(mx[2*x],mx[2*x+1]);}int get(int x) { int l=1,r=k+1,mid=(l+r)>>1; while (l+1<r) if (add[mid].x<=x) { l=mid;mid=(l+r)>>1; } else { r=mid;mid=(l+r)>>1; } return r;}int query(int x,int l,int r,int L,int R,int w) { if (L>R||mx[x]<=w) return 0; if (l==r) return l; int ret,mid=(l+r)>>1; if (R<=mid) return query(2*x,l,mid,L,R,w); else if (L>mid) return query(2*x+1,mid+1,r,L,R,w); else { ret=query(2*x,l,mid,L,mid,w); if (!ret) ret=query(2*x+1,mid+1,r,mid+1,R,w); return ret; }}int main(){ int i,n,x,y,z; scanf("%d", &n); for (i=1;i<=n;i++) { scanf("%s%d%d", s, &x, &y); if (s[0]=='a') { ope[i]=node(1,x,y);add[++k]=node(1,x,y); } else if (s[0]=='r') ope[i]=node(2,x,y); else { ope[i]=node(3,x,y);add[++k]=node(1,x,y); } } sort(add+1,add+k+1); build(1,1,k); for (i=1;i<=n;i++) if (ope[i].op==1) add_point(1,1,k,find_point(ope[i].x,ope[i].y),ope[i].y); else if (ope[i].op==2) del_point(1,1,k,find_point(ope[i].x,ope[i].y)); else { z=query(1,1,k,get(ope[i].x),k,ope[i].y); if (!z) printf("-1\n"); else printf("%d %d\n", add[z].x, add[z].y); } return 0;}
1 0
- Codeforces Beta Round #19 D. Points
- Codeforces Beta Round #19 D Points
- Codeforces Beta Round #19 D. Points
- Codeforces Beta Round #19D. Points
- Codeforces Beta Round #19 D. Points 线段树+离散化离散化
- Codeforces Beta Round #19 D线段树
- Codeforces Beta Round #19D 线段树
- Codeforces Beta Round #51 D
- codeforces 19D Points
- CodeForces 19D Points
- CodeForces 19D Points
- Codeforces 19D-Points
- codeforces Beta Round #19 D. Point (线段树 + set)
- Codeforces Beta Round #43 D. Parking Lot
- Codeforces Beta Round #14 D - Two Paths
- Codeforces Beta Round #43 D. Parking Lot
- Codeforces Beta Round #51 D. Beautiful numbers
- Codeforces Beta Round #7 D. Palindrome Degree
- mysql 空间计算
- 剑指offer(39):数字在排序数组中出现的次数
- [转]JAVA String 类
- Android Glide图片加载框架图片变色变绿解决方法
- android---高德地图(3)点击获得目的经纬度,地理编码
- Codeforces Beta Round #19D. Points
- tez跑任务报错
- 详解css中relative,absolute,float用法
- 全文索引----solr客户端工具solrJ
- android---高德地图(2)---定位-显示小蓝点
- HDU - 4277 USACO ORZ (set判重+dfs)好题
- 带动画效果的三方欢迎界面
- android---高德地图(1)---显示一张简单地图
- uva 10603 Fill 搜索