离散化,线段树。$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. Java凝视Override、Deprecated、SuppressWarnings详细解释

    一.什么是视线     说起目光,你必须先提什么是元数据(metadata). 所谓元数据是数据的数据.那.元数据是描述数据的叙述. 像在表中的数据字段,叙述了这个字段下的数据的含义.而J2SE5.0 ...

  2. mysql基础之基本数据类型

    原文:mysql基础之基本数据类型 列类型学习 mysql三大列类型 整型 Tinyint/ smallint/ mediumint/int/ bigint(M) unsigned zerofill ...

  3. 利用sqlclr实现数据库服务器端数据加密解密

    在公司中一同事用sqlclr写数据迁移自动化执行脚本,发现他在执行脚本时对数据进行了加密. 个人觉得利用sqlclr对数据进行加密是一个解决数据网络安全传输的不错的方案. 以下是一个小的案例: --- ...

  4. dcmtk常用命令

    dump2dcm 把普通文件转换成含有dcm头的文件,参数为源文件,目标文件 例:dump2dcm q1.txt query.dcm 表示把q1.txt文件转换为query.dcm dcmdump 阅 ...

  5. 基于A2DFramework的事件机制实现

    随笔- 102  文章- 3  评论- 476  发布订阅 - 基于A2DFramework的事件机制实现   SUMMARY 能做什么 DEMO 原理图 应用场景 能做什么 A2DFramework ...

  6. C语言指针操作

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/pointer-manipulation. ...

  7. Linq无聊练习系列3--聚合函数练习

    /**************聚合函数 练习*******************/            //求学生的总数量            var list = ctx.T_Student. ...

  8. 使用maven+eclipse搭建最简单的struts2的helloworld

    使用maven+eclipse搭建最简单的struts2的helloworld 一.web分层结构简介 1.web[细]粒度分层结构: 按细粒度分层可以分为以下6种: 1).表现层:html/css/ ...

  9. [转]Breaking Bad With DTrace

    Source:http://initwithfunk.com/blog/2013/05/31/breaking-bad-with-dtrace/ I’ve spent an unwise amount ...

  10. [转]Apple iPod, iPhone (2g, 3g), iPad Dock connector pinout

    Pin Signal Description Apple pin numbering* 1 GND Ground (-), internally connected with Pin 2 on iPo ...