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的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- Solr安装(Tomcat)
Solr安装(Tomcat) 安装环境 Windows 7 64bit Apache-tomcat-8.0.9-windows-x64 Solr-4.9.0 JDK 1.8.0_05 64bit ...
- php和cookie
cookie常用于用户识别,是服务器留在用户计算机中的小文件. cookie在浏览器端和服务器端的通信过程大致是这样: 浏览器向服务器作出请求(如果浏览器有cookie,将在request heade ...
- java class load
https://mp.weixin.qq.com/s?__biz=MjM5NzMyMjAwMA==&mid=403638649&idx=2&sn=4f17e8b58c64875 ...
- 逐步在Windows上结合CopSSH + msysGit安装安装Git Server同时集成Git使用Visual Studio
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...
- nant build
http://stackoverflow.com/questions/700871/publish-webapplication-using-nant <target name="co ...
- MacVim小试
Mac OS X使用之——新年第一天弘法寺许愿,MacVim小试 分类: Vi/Vim Mac OS X2013-01-01 22:08 3371人阅读 评论(0) 收藏 举报 目录(?)[+] ...
- noip模拟赛:电话时间[字符串]
[问题描述] 某人总是花很多时间给父母打电话.有一次他记录了打电话的开始时间和结束时刻t1和t2,请你帮他算算此次通话一共用了多少秒.又有一次,他记录了打电话的开始时刻t1和通话的时间长度len,请你 ...
- queue,指针求最短路的区别
这里以spfa为例://都用邻接表存边: 指针: int h=1,t=1; q[h]=x; while(h<=t){ int u=q[h]; vis[u]=0; for(int i=head[u ...
- Orchard学习
Data Source=.\SQLEXPRESS;Initial Catalog=Arale;Integrated Security=True;
- SOCKET网络编程细节问题3
SOCKET网络编程快速上手(二)——细节问题(3) 3.SIGPIPE问题 人怕牺牲,我们写的程序也一样,人有死不瞑目,程序又何尝不是?程序跑着跑着,突然就崩掉了.好一点的牺牲前告诉你些打印,差点的 ...