先看看上一个题:

题目大意是: 矩阵中有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. FusionCharts ajax 调用方式

    方式一:setJSONUrl function initChart() {                    var myChart = new FusionCharts("Fusion ...

  2. 本地电脑localhost指向127.0.0.1的配置

    windows系统电脑,我们如果想访问本机部署的项目,通常使用的是localhost来指向本机,但是有时候发现不行,我们不妨打开资源管理器,C:\Windows\System32\drivers\et ...

  3. hduacm 5104

    http://acm.hdu.edu.cn/show #include <cstdio> #include <cstring> #include <algorithm&g ...

  4. sql删除语句

    TRUNCATE TABLE Moisture_test 删除表里所有的数据,就连主键的自增也被删除delete Moisture_test 删除表里数据但是就连主键的自增没有被删除

  5. swift 开眼今日精选

    swift 开眼今日精选 import UIKit class TodayController: UITableViewController { vararray =NSMutableArray() ...

  6. P142-1

    P142-1.1 登录页面 <%@ page language="java" contentType="text/html; charset=UTF-8" ...

  7. JavaScript 自定义事件

    //自定义事件 function Event() { var handles = []; //绑定事件 this.addHandle=function(fn) { handles.push(fn); ...

  8. 使用ASP.Net WebAPI构建REST服务(六)——Self-Host

    Asp.Net WebAPI生成的是一个程序集,并不是独立的进程,因此,要运行的时候必须将其承载在相应的宿主上,一般比较常见的是IIS承载.很多时候,我们为了简化部署或者功能集成,需要将其承载到独立的 ...

  9. win10系统的点评

    Windows 10 是美国微软公司所研发的新一代跨平台及设备应用的操作系统.在正式版本发布一年内,所有符合条件的Windows7.Windows 8.1的用户都将可以免费升级到Windows 10, ...

  10. MATLAB图像处理函数汇总(一)

    1.applylut功能: 在二进制图像中利用lookup表进行边沿操作.语法:A = applylut(BW,lut)举例lut = makelut('sum(x(:)) == 4',2);BW1 ...