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的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- Lucene.net入门学习
Lucene.net入门学习(结合盘古分词) Lucene简介 Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全 ...
- hudson任务配置说明
hudson任务配置说明 Discard Old Builds:hudson默认保留过去的构建,勾选此选项,则可以设置构建记录的有效期: (帮助:这里控制着您想要在hudson所在的磁盘把构建记录存储 ...
- Linux内核编译和运行
内核获取网站:https://www.kernel.org/pub/linux/kernel/ 步骤如下: 1.打开终端,更改用户权限为root.具体做法是在终端输入sudo su,然后按提示输入 ...
- HBase的索引
LSM树由来.设计思想以及应用到HBase的索引 讲LSM树之前,需要提下三种基本的存储引擎,这样才能清楚LSM树的由来: 哈希存储引擎 是哈希表的持久化实现,支持增.删.改以及随机读取操作,但 ...
- Day4:T1小技巧(类似于指针操作)T2搜索+小细节
Day4:其中有很多小技巧get T1 一直没有听到过像这样的小技巧的略专业名词,有点类似于指针操作,之前有碰到过很多这样的题目 每次都是以不同的形式出现,但是感觉思想还是有点接近的吧(就比如某天有一 ...
- [转] Building xnu for OS X 10.10 Yosemite
Source:http://shantonu.blogspot.jp/2014/10/building-xnu-for-os-x-1010-yosemite.html The OS X kernel ...
- [转]Inspecting Obj-C parameters in gdb
Since the addition of i386 and x86_64 to the Mac OS’s repertoire several years back, remembering whi ...
- PHP中的赋值-引用or传值?
直接上代码: <?php $num1 = 1; $num2 = $num1; $num1 = 2; echo $num2 . "\n"; $arr1 = array(1, 2 ...
- defer 与 async
defer HTML4.01定义的 只适用于外部脚本(IE4~7会支持内嵌脚本的defer属性) 告诉浏览器立即下载,延迟执行,脚本会延迟到整个页面全部解析完毕之后才运行 HTML5规范要求脚本按照他 ...
- WCF学习笔记之传输安全
WCF学习笔记之传输安全 最近学习[WCF全面解析]下册的知识,针对传输安全的内容做一个简单的记录,这边只是简单的记录一些要点:本文的内容均来自[WCF全面解析]下册: WCF的传输安全主要涉及认证. ...