离散化,线段树。$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的更多相关文章

  1. UVALive 7141 BombX(离散化+线段树)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  4. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  5. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  6. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  7. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  8. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  9. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

随机推荐

  1. Asp.Net Identity 深度解析 之 注册登录的扩展

    关于权限每个系统都有自己的解决方案,今天我们来讨论一下微软的权限框架Asp.Net Identity ,介绍如下  http://www.asp.net/identity 这里不在赘余. 很多人认为 ...

  2. 18 个最新实用的 jQuery 插件

    1. Simple Effects for Drop-Down Lists 一个jQuery插件用于将普通的select控件转成一个带有一些简单扩展效果的下拉列表. 2. X-editable 这个插 ...

  3. tsung 对 openfire 压力测试

    tsung 对 openfire 压力测试   1. 参考 http://blog.csdn.net/foxisme2/article/details/7521139 http://blog.csdn ...

  4. 领域模型(Domain Model)

    领域模型(Domain Model) 一:面向对象设计中最简单的部分与最难的部分 如果说事务脚本是 面向过程 的,那么领域模型就是 面向对象 的.面向对象的一个很重要的点就是:“把事情交给最适合的类去 ...

  5. js urlencode , encodeURIComponent

    js 对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent ...

  6. SpringMVC 国际化

    SpringMVC学习系列(8) 之 国际化 在系列(7)中我们讲了数据的格式化显示,Spring在做格式化展示的时候已经做了国际化处理,那么如何将我们网站的其它内容(如菜单.标题等)做国际化处理呢? ...

  7. JSP技术模型(五)JSP隐含变量

    在JSP页面的转换阶段,容器在_jspService()方法中申明并初始化一些变量,可以在JSP页面小脚本中或表达式中直接使用这些变量. 一.JSP页面中可使用的隐含变量 1.applicationj ...

  8. D0

    刚到长乐就被机房里众大神的气场给压倒了 orz....... 然后默默的感觉到自己貌似已经有一个星期没有打题了...就各种忧伤.... 还是说一下今天的计划吧 嗯傍晚5.30-6.00 &&a ...

  9. cocos2d-x C++的do...while(0)另类使用方法

    在C++中,有三种类型的循环语句:for, while, 和do...while, 但是在一般应用中作循环时, 我们可能用for和while要多一些,do...while相对不受重视.      但是 ...

  10. c语言:最长对称子串(3种解决方案)

    问题描述: 输入一个字符串,输出该字符串中最大对称子串的长度.例如输入字符串:“avvbeeb”,该字符串中最长的子字符串是“beeb”,长度为4,因而输出为4. 解决方法:中序遍历 一,全遍历的方法 ...