离散化,线段树。$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. PHP+MYSQL分页原理

    1.SQL语句中的limit用法 2.学习分页的一种公式 3.parse_url()解析URL函数 parse_url() 是将URL解析成有固定键值的数组的函数 4.$_SERVER["R ...

  2. 在SQL Server中添加Linked Server 图解版

    在开发中,经常需要一个SQL Server服务器去访问另一个服务器,微软提供了一种方式Linked Server 下面是配置流程: 1).打开Server Objects下 Linked Server ...

  3. Linq无聊练习系列1--where练习

    linq主要有3种,linq to sql,linq to XML,Linq to Object linq to sql. 这里没有通过相应的类,生成相应的数据库中的表.没有用流行的编码优先. 只是为 ...

  4. 玩转python之每次处理一个字符

    在Python中字符就是长度为1的字符串,所以可以循环遍历一个字符串,依次访问每一个字符,得到你想要的处理前提: 一个列表是个好主意,就像这样:thelist = list(thestring) 当然 ...

  5. 把《C语言接口与实现》读薄之第一章:引言

    1.1文学程序 文学程序(literate program):接口及其实现的代码与对其进行解释的正文交织在一起.文学程序由英文正文和带标签的程序代码块组成.例如, 〈compute x * y〉≡ s ...

  6. android通过程序收起通知栏

    1.  添加权限 <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" /> 2. ...

  7. 1 MySQL概述

    目录: 1. 简述 2. 历史 3. 同类产品 4. 优点和不足 5. MySQL存储引擎 6. MySQL架构 1. 简述 MySQL是一个关系型数据库管理系统.其体积小,速度快,开发源代码,使用成 ...

  8. String和StringBuilder的使用

    如果有理解错误的地方希望有朋友能指出,谢谢!   String是特殊的引用类型的,更像值类型,StringBuilder的是规规矩矩引用类型的.   首先看这样的对比图,Equals()方法是判断两个 ...

  9. Python实现LDAP用户名密码验证

    网上借鉴了不少东西,下面是python代码,备份后用. 思路,因为每个用户的组都不一样,这样就导致了dn不一致的情况, 据需要先根据用户名获取该用户的dn,然后再bind用户名和密码进行验证. 反正是 ...

  10. 迟到的 WPF 学习 —— 路由事件

    1. 理解路由事件:WPF 通过事件路由(event routing)概念增强了传统的事件执行的能力和范围,允许源自某个元素的事件由另一个元素引发,例如,事件路由允许工具栏上的一个按钮点击的事件在被代 ...