Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0, 0) is located in the bottom-left corner, Ox axis is directed right, Oy axis is directed up. Pete gives Bob requests of three types:

  • add x y — on the sheet of paper Bob marks a point with coordinates (x, y). For each request of this type it's guaranteed that point(x, y) is not yet marked on Bob's sheet at the time of the request.
  • remove x y — on the sheet of paper Bob erases the previously marked point with coordinates (x, y). For each request of this type it's guaranteed that point (x, y) is already marked on Bob's sheet at the time of the request.
  • find x y — on the sheet of paper Bob finds all the marked points, lying strictly above and strictly to the right of point (x, y). Among these points Bob chooses the leftmost one, if it is not unique, he chooses the bottommost one, and gives its coordinates to Pete.

Bob managed to answer the requests, when they were 10, 100 or 1000, but when their amount grew up to 2·105, Bob failed to cope. Now he needs a program that will answer all Pete's requests. Help Bob, please!

Input

The first input line contains number n (1 ≤ n ≤ 2·105) — amount of requests. Then there follow n lines — descriptions of the requests.add x y describes the request to add a point, remove x y — the request to erase a point, find x y — the request to find the bottom-left point. All the coordinates in the input file are non-negative and don't exceed 109.

Output

For each request of type find x y output in a separate line the answer to it — coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (x, y). If there are no points strictly above and to the right of point (x, y), output -1.

Sample Input

Input
  1. 7
    add 1 1
    add 3 4
    find 0 0
    remove 1 1
    find 0 0
    add 1 1
    find 0 0
Output
  1. 1 1
    3 4
    1 1
Input
  1. 13
    add 5 5
    add 5 6
    add 5 7
    add 6 5
    add 6 6
    add 6 7
    add 7 5
    add 7 6
    add 7 7
    find 6 6
    remove 7 7
    find 6 6
    find 4 4
Output
  1. 7 7
    -1
    5 5
  2.  
  3. 题解:
    线段树维护
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int maxn = 2e5 + ;
  5. typedef pair < int ,int > dii;
  6. struct operation
  7. {
  8. int x , y , tp ;
  9. }op[maxn];
  10. char str[];
  11. int c,n,QueryY;
  12.  
  13. vector < int > vi;
  14. set < int > :: iterator it , it2;
  15.  
  16. struct Segmenttree
  17. {
  18. typedef int SgTreeDataType;
  19. struct treenode
  20. {
  21. int L , R ;
  22. SgTreeDataType maxy;
  23. set < int > s;
  24. void updata(SgTreeDataType v){
  25. s.insert(v);
  26. maxy=max(maxy,v);
  27. }
  28. void remove(SgTreeDataType v){
  29. s.erase(v);
  30. if(s.empty()) maxy=;
  31. else{
  32. it=s.end();it--;
  33. maxy=*it;
  34. }
  35. }
  36. };
  37.  
  38. treenode tree[maxn * ];
  39.  
  40. inline void push_up(int o){
  41. int lson = o << , rson = o << | ;
  42. tree[o].maxy=max(tree[lson].maxy,tree[rson].maxy);
  43. }
  44.  
  45. void build(int L , int R , int o){
  46. tree[o].L = L , tree[o].R = R,tree[o].maxy=;tree[o].s.empty();
  47. if (R > L){
  48. int mid = (L+R) >> ;
  49. build(L,mid,o<<);
  50. build(mid+,R,o<<|);
  51. }
  52. }
  53.  
  54. void updata(int p,SgTreeDataType v,int o){
  55. int L = tree[o].L , R = tree[o].R;
  56. if (L==R) tree[o].updata(v);
  57. else{
  58. int mid = (L+R)>>;
  59. if (p <= mid) updata(p,v,o<<);
  60. else updata(p,v,o<<|);
  61. push_up(o);
  62. }
  63. }
  64.  
  65. void remove(int p,SgTreeDataType v,int o){
  66. int L = tree[o].L , R = tree[o].R;
  67. if (L==R) tree[o].remove(v);
  68. else{
  69. int mid = (L+R)>>;
  70. if (p <= mid) remove(p,v,o<<);
  71. else remove(p,v,o<<|);
  72. push_up(o);
  73. }
  74. }
  75.  
  76. dii query(int p,int o){
  77. int L = tree[o].L , R = tree[o].R;
  78. if (L>=p){
  79. int lson = o << , rson = o << | ;
  80. if(tree[o].maxy > QueryY){
  81. if(L==R){
  82. it = tree[o].s.upper_bound(QueryY);
  83. return make_pair( L , *it);
  84. }else{
  85. if(tree[lson].maxy > QueryY) return query(p , lson);
  86. else if(tree[rson].maxy > QueryY) return query(p , rson);
  87. }
  88. }else return make_pair(-,-);
  89. }
  90. else{
  91. int mid = (L+R)>>;
  92. dii res(-,-);
  93. if (p <= mid) res = query(p,o<<);
  94. if(~res.first) return res;
  95. return query(p,o<<|);
  96. }
  97. }
  98. }Sgtree;
  99.  
  100. inline int GetRank(int x){
  101. return lower_bound( vi.begin() , vi.begin() + c , x ) - vi.begin();
  102. }
  103.  
  104. int main(int argc,char *argv[]){
  105. scanf("%d",&n);
  106. for(int i = ; i <= n ; ++ i){
  107. int x , y;
  108. scanf("%s%d%d",str,&op[i].x,&op[i].y);
  109. if(str[]=='a') op[i].tp = ;
  110. else if(str[]=='r') op[i].tp = ;
  111. else op[i].tp = ;
  112. vi.push_back(op[i].x);
  113. }
  114. sort( vi.begin() , vi.end() );
  115. c = unique( vi.begin() , vi.end() ) - vi.begin();
  116. Sgtree.build( , c - , );
  117. for(int i = ; i <= n ; ++ i){
  118. op[i].x = GetRank( op[i].x );
  119. if(op[i].tp==) Sgtree.updata(op[i].x,op[i].y,);
  120. else if(op[i].tp==) Sgtree.remove(op[i].x,op[i].y,);
  121. else{
  122. if(op[i].x == c - ){
  123. printf("-1\n");
  124. continue;
  125. }
  126. QueryY = op[i].y;
  127. dii ans = Sgtree.query(op[i].x + , );
  128. if(ans.first==-) printf("-1\n");
  129. else printf("%d %d\n",vi[ans.first],ans.second);
  130. }
  131. }
  132. return ;
  133. }

CodeForces 19D Points的更多相关文章

  1. CodeForces 19D Points (线段树+set)

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  2. CodeForces 19D Points(离散化+线段树+单点更新)

    题目链接: huangjing 题意:给了三种操作 1:add(x,y)将这个点增加二维坐标系 2:remove(x,y)将这个点从二维坐标系移除. 3:find(x,y)就是找到在(x,y)右上方的 ...

  3. CodeForces 19D Points(线段树+map)

    开始想不通,后来看网上说是set,就有一个想法是对每个x建一个set...然后又想直接建立两重的set就好,最后发现不行,自己想多了...  题意是给你三种操作:add (x y) 平面添加(x y) ...

  4. codeforces 19D D. Points 树套树

    D. Points Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...

  5. Codeforces Beta Round #19D(Points)线段树

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  6. codeforces 872E. Points, Lines and Ready-made Titles

    http://codeforces.com/contest/872/problem/E E. Points, Lines and Ready-made Titles time limit per te ...

  7. codeforces 251A Points on Line(二分or单调队列)

    Description Little Petya likes points a lot. Recently his mom has presented him n points lying on th ...

  8. CodeForces 577E Points on Plane(莫队思维题)

    题目描述 On a plane are nn points ( x_{i}xi​ , y_{i}yi​ ) with integer coordinates between 00 and 10^{6} ...

  9. 『ACM C++』 Codeforces | 1066A - Points in Segments

    大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...

随机推荐

  1. 使用git上传项目到github

    来自: http://www.cnblogs.com/specter45/p/github.html GitHub是基于git实现的代码托管.git是目前最好用的版本控制系统了,非常受欢迎,比之svn ...

  2. 远程连接mysql,mysql如何开启远程连接

    很多时候,mysql只需要开本地连接,也就是本机(服务器本身)连接就可以,默认也是这样,默认也不支持远程连接 但有的时候,我们需要将mysql独立出一台主机或数据库,放到另一台机器的时候,这时,就需要 ...

  3. Sublime Text2 按shift键选择不了的问题

    记录下来,免得以后忘了: 今天在Sublime Text 2装了一个ThinkPHP插件之后.发现按shift键+鼠标左键选择不了内容了.原因是ThinkPHP里的热键与系统的有冲突了,须要设置例如以 ...

  4. OC与JS互相调用

    近期项目中要用到html5来实现.涉及到OC调用JS,以及JS调用OC的方法.这里把遇到的问题以及实现方法介绍一下. // // ViewController.h // OC_And_JS // // ...

  5. 升级Android ADT 和SDK

    因为眼下从事android开发工作,所以升级了下Android SDK和eclipse ADT插件 一.更新ADT 1.Eclipse中打开Help->Install New Software. ...

  6. 数据库系统原理及其应用总结---ShinePans

    第一章  数据库概论 1.在数据库管理技术的发展过程中.数据库独立性最高的是"数据库系统"阶段 2.三大经典的数据结构模型是"关系.层次和网状模型" 3.单个用 ...

  7. [小技巧] Python 脚本暴力破解 HC2600 机顶盒管理密码

    家里最近接入了广电有线电视,配了三个创维 HC2600 机顶盒,并且每个机顶盒还带有无线路由器功能. 免费赠送 Internet 接入服务倒也没什么,不过机顶盒内置的 WIFI 实在有点寒酸:只支持 ...

  8. display属性解析

    none 此元素不会被显示 block 此元素将显示为块级元素,此元素前后会带有换行符. inline 默认.此元素会被显示为内联元素,元素前后没有换行符. inline-block 行内块元素.(C ...

  9. VritualBox 中Debian安装tool

    VritualBox 中Debian安装tool 环境 Debian 8 VirtualBox 配置Debian的源 #163源 deb http://mirrors.163.com/debian/ ...

  10. (转)passwordStrength 基于jquery的密码强度检测代码使用介绍

    使用很简单. 代码如下: $('#pass').passwordStrength();  XHTML 代码如下: <p><label>请输入密码:</label>  ...