先看看上一个题:

题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条件的元素,先比较X,选择X最小的那个,如果还是有很多满足条件的元素,再比较Y,选择Y最小的元素,如果不存在就输出两个-1;

分析: 直接暴力就行了

这个题目大意:

这个题是上个题的坚强版,每次会增加或减少一个点,仍然找到一个元素E(X,Y),使得X>x并且Y>y;

最多有200000次操作,每次只能是O(logn)的查询,行有1000000000之大,但是最多只会出现200000个不同的行,所以要离散化一下。然后对于每行的所有列用set去存,用线段树来维护每一行的出现的最大列,具体看代码吧

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#define MAXN 200010 using namespace std; int Max[MAXN<<], b[MAXN], c[MAXN], cnt;
set<int>sy[MAXN];
struct node
{
int x, y, flag;
} n[];
void PushUp(int root)
{
Max[root]=max(Max[root*],Max[root*+]);
}
void Update(int p, int x, int L, int R, int root) //a[p]=x,并且更新最大值
{
if(L==R)
{
Max[root]=x;
return ;
}
int mid=(L+R)/;
if(p<=mid) Update(p,x,L,mid,root*);
else Update(p,x,mid+,R,root*+);
PushUp(root);
}
int Query(int num, int post_ll, int L, int R, int root)//从post_ll这个位置开始向右查找,返回大于等于num的位置下表
{
if(L==R)
{
if(Max[root]>=num) return L;
else return -;
}
int ans=-, mid=(L+R)/;
if(post_ll<=mid&&Max[root*]>=num) ans=Query(num,post_ll,L,mid,root*);
if(ans!=-) return ans;
if(Max[root*+]>=num) ans=Query(num,post_ll,mid+,R,root*+);
return ans;
} int BS1(int x)
{
int low=, high=cnt, mid;
while(low<=high)
{
mid=low+high>>;
if(c[mid]==x) return mid;
else if(c[mid]>x) high=mid-;
else low=mid+;
}
}
int BS2(int x)
{
int low=, high=cnt, mid, ans=-;
while(low<=high)
{
mid=low+high>>;
if(c[mid]>x)
{
ans=mid;
high=mid-;
}
else low=mid+;
}
return ans;
}
void init(int nn)
{
for(int i=; i<nn; i++)
sy[i].clear();
memset(Max,-,sizeof(Max));
}
int main()
{
int nn, x, tot, ans, cas=;
char cmd[];
while(scanf("%d",&nn)!=EOF&&nn)
{
cnt=tot=;
init(nn);
for(int i=; i<nn; i++)
{
scanf("%s%d%d",cmd,&n[i].x,&n[i].y);
if(!strcmp(cmd,"add"))
{
n[i].flag=;
b[tot++]=n[i].x;
}
else if(!strcmp(cmd,"find"))
n[i].flag=;
else n[i].flag=;
}
sort(b,b+tot);
c[]=b[];
for(int i=; i<tot; i++)
{
if(b[i]!=b[i-])
c[++cnt]=b[i];
}//离散化
printf("Case %d:\n",++cas);
for(int i=; i<nn; i++)
{
if(n[i].flag==)
{
x=BS1(n[i].x);
sy[x].insert(n[i].y);
Update(x,*(--sy[x].end()),,cnt,);
}
else if(n[i].flag==)
{
x=BS2(n[i].x);
if(x==-)
{
puts("-1");
continue ;
}
ans=Query(n[i].y+,x,,cnt,);
if(ans==-) printf("-1\n");
else printf("%d %d\n",c[ans],*(sy[ans].lower_bound(n[i].y+)));
}
else
{
x=BS1(n[i].x);
sy[x].erase(n[i].y);
if(!sy[x].size())
{
Update(x,-,,cnt,);
}
else Update(x,*(--sy[x].end()),,cnt,);
}
}
printf("\n");
}
return ;
}

sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散的更多相关文章

  1. sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)

    题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...

  2. Hello World! 2010年山东省第一届ACM大学生程序设计竞赛

    Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...

  3. 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)

    题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...

  4. Phone Number 2010年山东省第一届ACM大学生程序设计竞赛

    Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...

  5. [2011山东省第二届ACM大学生程序设计竞赛]——Identifiers

    Identifiers Time Limit: 1000MS Memory limit: 65536K 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?act ...

  6. sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛

    Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There ...

  7. [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !

    n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Lim ...

  8. angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...

  9. [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number

    Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...

随机推荐

  1. (转)onTouchEvent方法的使用

      (转)onTouchEvent方法的使用 手机屏幕事件的处理方法onTouchEvent.该方法在View类中的定义,并且所有的View子类全部重写了该方法,应用程序可以通过该方法处理手机屏幕的触 ...

  2. windows常见已知熟悉操作命令

    WIN+R--->输入CMD---->回车有关某个命令的详细信息,请键入 HELP 命令名ASSOC          显示或修改文件扩展名关联.ATTRIB         显示或更改文 ...

  3. 二模 (3) day2

    第一题: 题目大意:(难以概括,就不贴了把.) 解题过程: 1.担心被精度问题恶心,就把平均数的地方乘了N,这样只有最后计算的时候才会是小数.. 2.数组保存的时候蛋疼的 没改成double.结果全部 ...

  4. https://github.com/oneuijs/You-Dont-Need-jQuery

    https://github.com/oneuijs/You-Dont-Need-jQuery

  5. node开发 npm install -g express-generator@4

    Node forever : 1,forever start --uid test start app.js 2,forever start --uid test start -a app.js 3, ...

  6. Java对象的序列化和反序列化实践

    2013-12-20 14:58 对象序列化的目标是将对象保存在磁盘中,或者允许在网络中直接传输对象.对象序列化机制允许把内存中的Java对象转换成平台无关的二进制流,从而允许把这种二进制流持久的保存 ...

  7. 表(list)

    表 表(list)是常见的数据结构.从数学上来说,表是一个有序的元素集合.在C语言的内存中,表储存为分散的节点(node).每个节点包含有一个元素,以及一个指向下一个(或者上一个)元素的指针.如下图所 ...

  8. 有哪些 PHP 调试技巧?

    我目前遇到的最让我称赞的debug方式是:xdebug的 xdebug_start_trace(); /* 业务代码 */ xdebug_stop_trace(); 他解决了我长久以来一个代码调试问题 ...

  9. 2014年3月份第1周51Aspx源码发布详情

    Graphics创建饼图示例源码  2014-3-7 [VS2010]源码描述:这个程序是一个在c#中使用图形类用来创建饼图,此程序是用Graphics 类的DrawPie() 和 FillPie() ...

  10. poj2193

    //Accepted 368K 532MS //线性dp //dp[i][j]表示前i位最后一个是j的排列数 //dp[i][j]=sum(dp[i-1][h]) h*2<=j #include ...