离散化,线段树。$2014$年$ACM/ICPC$亚洲区域赛上海站$D$题。

可以处理出炸任意相邻的$h$行能消灭的点的数量,以及炸任意相邻的$w$列能消灭的点的数量,分别用$py[i]$和$px[i]$记。

然后可以枚举炸哪个相邻的$h$行,这相邻的$h$行中有些位置可能有点在,所以有一些位置的$px$值是不可取的,要将这些$px$删去之后找一个最大值$m$,利用$m+py[i]$更新答案。一个点会导致一段连续的$px$不可取,所以可以用线段树区间更新将这一段区间的值减去一个比$n$大的值,使得这一段区间的值都是负的。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<vector>
  4. #include<algorithm>
  5. #include<iostream>
  6. using namespace std;
  7.  
  8. const int maxn=3e5+;
  9. int n,w,h;
  10. struct Point
  11. {
  12. int x,y;
  13. void read() { scanf("%d%d",&x,&y); }
  14. }p[maxn];
  15. vector<int>x,y,in[maxn],out[maxn];
  16. int px[maxn],py[maxn],W,H,ans;
  17.  
  18. long long s[maxn*],f[maxn*];
  19.  
  20. void build(int l,int r,int rt)
  21. {
  22. f[rt]=;
  23. if(l==r) { s[rt]=px[l]; return ; }
  24.  
  25. int m=(l+r)/;
  26. build(l,m,*rt);
  27. build(m+,r,*rt+);
  28.  
  29. s[rt]=max(s[*rt],s[*rt+]);
  30. }
  31.  
  32. void pushDown(int rt)
  33. {
  34. if(f[rt]==) return ;
  35.  
  36. s[*rt]+=f[rt], f[*rt]+=f[rt];
  37. s[*rt+]+=f[rt], f[*rt+]+=f[rt];
  38. f[rt]=;
  39. }
  40.  
  41. void update(int L,int R,int val,int l,int r,int rt)
  42. {
  43. if(L<=l&&r<=R) { s[rt]+=val, f[rt]+=val; return ; }
  44.  
  45. int m=(l+r)/;
  46. pushDown(rt);
  47.  
  48. if(L<=m) update(L,R,val,l,m,*rt);
  49. if(R>m) update(L,R,val,m+,r,*rt+);
  50.  
  51. s[rt]=max(s[*rt],s[*rt+]);
  52. }
  53.  
  54. int get(int g,bool flag)
  55. {
  56. if(flag==) return lower_bound(x.begin(),x.end(),g)-x.begin()+;
  57. return lower_bound(y.begin(),y.end(),g)-y.begin()+;
  58. }
  59.  
  60. int main()
  61. {
  62. int T,cas=; scanf("%d",&T);
  63. while(T--)
  64. {
  65. scanf("%d%d%d",&n,&w,&h);
  66. for(int i=;i<=n;i++) p[i].read(); x.clear(); y.clear();
  67. for(int i=;i<=n;i++)
  68. {
  69. y.push_back(p[i].y); y.push_back(p[i].y-h+); y.push_back(p[i].y+);
  70. x.push_back(p[i].x); x.push_back(p[i].x-w+); x.push_back(p[i].x+);
  71. }
  72. sort(x.begin(),x.end()); x.erase(unique(x.begin(),x.end()),x.end());
  73. sort(y.begin(),y.end()); y.erase(unique(y.begin(),y.end()),y.end());
  74.  
  75. memset(px,,sizeof px); memset(py,,sizeof py);
  76.  
  77. W=x.size(); H=y.size();
  78. for(int i=;i<=H;i++) { in[i].clear(); out[i].clear(); }
  79.  
  80. for(int i=;i<=n;i++)
  81. {
  82. int xx=get(p[i].x-w+,), yy=get(p[i].y-h+,);
  83. int xxx=get(p[i].x+,), yyy=get(p[i].y+,);
  84. px[xx]++; px[xxx]--; py[yy]++; py[yyy]--;
  85. in[yy].push_back(i); out[yyy-].push_back(i);
  86. }
  87.  
  88. ans=;
  89. for(int i=;i<=W;i++) px[i]=px[i]+px[i-], ans=max(ans,px[i]);
  90. for(int i=;i<=H;i++) py[i]=py[i]+py[i-], ans=max(ans,py[i]);
  91.  
  92. build(,W,);
  93.  
  94. for(int i=;i<=H;i++)
  95. {
  96. for(int j=;j<in[i].size();j++)
  97. {
  98. int ll=get(p[in[i][j]].x-w+,), rr=get(p[in[i][j]].x,);
  99. update(ll,rr,-n,,W,);
  100. }
  101.  
  102. if(s[]>) ans=max(ans,py[i]+(int)s[]);
  103.  
  104. for(int j=;j<out[i].size();j++)
  105. {
  106. int ll=get(p[out[i][j]].x-w+,), rr=get(p[out[i][j]].x,);
  107. update(ll,rr,n,,W,);
  108. }
  109. }
  110. printf("Case #%d: %d\n",cas++,ans);
  111. }
  112. return ;
  113. }

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. Lucene.net入门学习

    Lucene.net入门学习(结合盘古分词)   Lucene简介 Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全 ...

  2. hudson任务配置说明

    hudson任务配置说明 Discard Old Builds:hudson默认保留过去的构建,勾选此选项,则可以设置构建记录的有效期: (帮助:这里控制着您想要在hudson所在的磁盘把构建记录存储 ...

  3. Linux内核编译和运行

      内核获取网站:https://www.kernel.org/pub/linux/kernel/ 步骤如下: 1.打开终端,更改用户权限为root.具体做法是在终端输入sudo su,然后按提示输入 ...

  4. HBase的索引

    LSM树由来.设计思想以及应用到HBase的索引   讲LSM树之前,需要提下三种基本的存储引擎,这样才能清楚LSM树的由来: 哈希存储引擎  是哈希表的持久化实现,支持增.删.改以及随机读取操作,但 ...

  5. Day4:T1小技巧(类似于指针操作)T2搜索+小细节

    Day4:其中有很多小技巧get T1 一直没有听到过像这样的小技巧的略专业名词,有点类似于指针操作,之前有碰到过很多这样的题目 每次都是以不同的形式出现,但是感觉思想还是有点接近的吧(就比如某天有一 ...

  6. [转] 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 ...

  7. [转]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 ...

  8. PHP中的赋值-引用or传值?

    直接上代码: <?php $num1 = 1; $num2 = $num1; $num1 = 2; echo $num2 . "\n"; $arr1 = array(1, 2 ...

  9. defer 与 async

    defer HTML4.01定义的 只适用于外部脚本(IE4~7会支持内嵌脚本的defer属性) 告诉浏览器立即下载,延迟执行,脚本会延迟到整个页面全部解析完毕之后才运行 HTML5规范要求脚本按照他 ...

  10. WCF学习笔记之传输安全

    WCF学习笔记之传输安全 最近学习[WCF全面解析]下册的知识,针对传输安全的内容做一个简单的记录,这边只是简单的记录一些要点:本文的内容均来自[WCF全面解析]下册: WCF的传输安全主要涉及认证. ...