UVALive 7141 BombX
离散化,线段树。$2014$年$ACM/ICPC$亚洲区域赛上海站$D$题。
可以处理出炸任意相邻的$h$行能消灭的点的数量,以及炸任意相邻的$w$列能消灭的点的数量,分别用$py[i]$和$px[i]$记。
然后可以枚举炸哪个相邻的$h$行,这相邻的$h$行中有些位置可能有点在,所以有一些位置的$px$值是不可取的,要将这些$px$删去之后找一个最大值$m$,利用$m+py[i]$更新答案。一个点会导致一段连续的$px$不可取,所以可以用线段树区间更新将这一段区间的值减去一个比$n$大的值,使得这一段区间的值都是负的。
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std; const int maxn=3e5+;
int n,w,h;
struct Point
{
int x,y;
void read() { scanf("%d%d",&x,&y); }
}p[maxn];
vector<int>x,y,in[maxn],out[maxn];
int px[maxn],py[maxn],W,H,ans; long long s[maxn*],f[maxn*]; void build(int l,int r,int rt)
{
f[rt]=;
if(l==r) { s[rt]=px[l]; return ; } int m=(l+r)/;
build(l,m,*rt);
build(m+,r,*rt+); s[rt]=max(s[*rt],s[*rt+]);
} void pushDown(int rt)
{
if(f[rt]==) return ; s[*rt]+=f[rt], f[*rt]+=f[rt];
s[*rt+]+=f[rt], f[*rt+]+=f[rt];
f[rt]=;
} void update(int L,int R,int val,int l,int r,int rt)
{
if(L<=l&&r<=R) { s[rt]+=val, f[rt]+=val; return ; } int m=(l+r)/;
pushDown(rt); if(L<=m) update(L,R,val,l,m,*rt);
if(R>m) update(L,R,val,m+,r,*rt+); s[rt]=max(s[*rt],s[*rt+]);
} int get(int g,bool flag)
{
if(flag==) return lower_bound(x.begin(),x.end(),g)-x.begin()+;
return lower_bound(y.begin(),y.end(),g)-y.begin()+;
} int main()
{
int T,cas=; scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&w,&h);
for(int i=;i<=n;i++) p[i].read(); x.clear(); y.clear();
for(int i=;i<=n;i++)
{
y.push_back(p[i].y); y.push_back(p[i].y-h+); y.push_back(p[i].y+);
x.push_back(p[i].x); x.push_back(p[i].x-w+); x.push_back(p[i].x+);
}
sort(x.begin(),x.end()); x.erase(unique(x.begin(),x.end()),x.end());
sort(y.begin(),y.end()); y.erase(unique(y.begin(),y.end()),y.end()); memset(px,,sizeof px); memset(py,,sizeof py); W=x.size(); H=y.size();
for(int i=;i<=H;i++) { in[i].clear(); out[i].clear(); } for(int i=;i<=n;i++)
{
int xx=get(p[i].x-w+,), yy=get(p[i].y-h+,);
int xxx=get(p[i].x+,), yyy=get(p[i].y+,);
px[xx]++; px[xxx]--; py[yy]++; py[yyy]--;
in[yy].push_back(i); out[yyy-].push_back(i);
} ans=;
for(int i=;i<=W;i++) px[i]=px[i]+px[i-], ans=max(ans,px[i]);
for(int i=;i<=H;i++) py[i]=py[i]+py[i-], ans=max(ans,py[i]); build(,W,); for(int i=;i<=H;i++)
{
for(int j=;j<in[i].size();j++)
{
int ll=get(p[in[i][j]].x-w+,), rr=get(p[in[i][j]].x,);
update(ll,rr,-n,,W,);
} if(s[]>) ans=max(ans,py[i]+(int)s[]); for(int j=;j<out[i].size();j++)
{
int ll=get(p[out[i][j]].x-w+,), rr=get(p[out[i][j]].x,);
update(ll,rr,n,,W,);
}
}
printf("Case #%d: %d\n",cas++,ans);
}
return ;
}
UVALive 7141 BombX的更多相关文章
- UVALive 7141 BombX(离散化+线段树)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- Memcache存储大量数据的问题
Memcache存储大数据的问题 huangguisu Memcached存储单个item最大数据是在1MB内,假设数据超过1M,存取set和get是都是返回false,并且引起性能的问题. 我们之 ...
- wp7学习笔记
1.xap:最终是压缩包:最终部署有系统控制,防止流亡软件:放到固有位置productid;有的文件放在.dll中或直接放入目录下:控制有生成操作:content,内容,content效率更高不用从. ...
- NET框架SOA解决方案(集Windows服务、WinForm形式与IIS形式发布)-分布式应用
NET框架SOA解决方案(集Windows服务.WinForm形式与IIS形式发布)-分布式应用 RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架,给用户和开发者最佳的.N ...
- (转载)Log4Net 在多层项目中的使用小记
(原创)Log4Net 在多层项目中的使用小记 这几天刚好在调整一个项目,把一些自己不是很清楚的东西先试验一下,这篇文章主要是对我在项目中需要使用Log4Net的一些记录.网上有很多相关的教程,但是各 ...
- 使用ReSharper打造团队代码
当前标签: 漂亮代码 请看高质量的代码——更新 Leo C.W 2014-04-01 19:16 阅读:544 评论:5 我们的终极编码规范 Leo C.W 2014-03-31 22:34 ...
- 2014.3.5-C语言学习小结
知识点: 1.结构体 struct 2.联合体 union 3.枚举 4.结构.联合与函数 =========================== 结构体 思考:如果现在希望保存一个学生的信息,该如何 ...
- UML类图的常见关系1
设计模式之UML类图的常见关系(一) 本篇会讲解在UML类图中,常见几种关系: 泛化(Generalization),依赖(Dependency),关联(Association),聚合(Aggre ...
- HashTable
算法打基础——HashTable 这一节主要讲很多方面非常重要的hash table等问题. 由于平时很少用到这些,基本都忘了... 怎样快速的在内存中插入.删除.和搜索呢? 这就需要哈希表了 这一节 ...
- 企业架构研究总结(41)——企业架构与建模之ArchiMate的由来和详述(上)
终于完成了关于企业架构框架理论的总结,谢谢各位看官的支持,能挺过之前过于理论化的叙述而坚持到现在着实不易,笔者也自愧没有实践经验可以分享,希望日后有兴趣的看官能够不吝赐教.在本系列后面的也是最后一个大 ...
- jQuery extend函数详解
一 jQuery的扩展方法原型是 $.extend(dest,src1,src2,src3); 含义是将src1,src2,src3合并到dest中,返回值为合并后的dest,该方法合并后,dest的 ...