poj 2528Mayor's posters
http://poj.org/problem?id=2528
这个题有个细节,整个区间的长度为10000000,而n最大只有1000,所以我们要进行离散化。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 10010
using namespace std; bool tab[maxn];
int l[maxn],r[maxn],x[maxn*],num[maxn*],tree[maxn*];
int c,n; int binary_search1(int sum)
{
int l=,r=*n;
while(l<=r)
{
int mid=(l+r)/;
if(x[mid]<=sum)
l=mid+;
else
r=mid-;
}
return num[r];
} void update(int i)
{
if(!tree[i])
return ;
tree[i+i]=tree[i+i+]=tree[i];
tree[i]=;
}
void change(int tl,int tr,int l,int r,int i,int co)
{
if(tl>r||tr<l) return ;
if(tl<=l&&r<=tr)
{
tree[i]=co;
return ;
}
update(i);
int mid=(l+r)/;
change(tl,tr,l,mid,i+i,co);
change(tl,tr,mid+,r,i+i+,co);
}
int require(int l,int r,int i)
{
int mid=(l+r)/;
if(tree[i])
{
if(!tab[tree[i]])
{
tab[tree[i]]=;
return ;
}
return ;
}
if(l==r)
return ;
return require(l,mid,i+i)+require(mid+,r,i+i+);
}
void init()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d%d",l+i,r+i);
x[i*-]=l[i];x[i*-]=r[i];x[i*]=(l[i]+r[i])/;
}
sort(x+,x+*n+);
memset(num,,sizeof(num));
for(int i=; i<=*n; i++)
{
num[i]=num[i-];
if(x[i]!=x[i-]) num[i]++;
}
for(int i=; i<=n; i++)
{
l[i]=binary_search1(l[i]);
r[i]=binary_search1(r[i]);
}
} void solve()
{
memset(tree,,sizeof(tree));
for(int i=; i<=n; i++)
{
change(l[i],r[i],,*n,,i);
}
memset(tab,,sizeof(tab));
int ans=require(,*n,);
printf("%d\n",ans);
} int main()
{
scanf("%d",&c);
while(c--)
{
init();
solve();
}
return ;
}
poj 2528Mayor's posters的更多相关文章
- Poj 2528-Mayor's posters 线段切割
题目:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ - 2528Mayor's posters (离散化+线段树区间覆盖)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- POJ 2528 Mayor's posters
Mayor's posters Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59239 Accepted: 17157 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- POJ 2528 - Mayor's posters - [离散化+区间修改线段树]
题目链接:http://poj.org/problem?id=2528 Time Limit: 1000MS Memory Limit: 65536K Description The citizens ...
- POJ:2528(Mayor's posters)离散化成段更新+简单哈希
http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that the ca ...
随机推荐
- java 吞吐量
jvm中 ,执行用户的代码占 的时间/总时间 ,假如前者是99 分钟,后者一分钟,则吞吐量为99% ,吞吐量越大.系统越好,如何设计系统,导致系统吞吐量高,因为我们知道,垃圾回收,7种垃圾收集器,也不 ...
- java.lang.NoClassDefFoundError: com/ibatis/sqlmap/engine/mapping/result/BasicResultMap
错误日志: java.lang.NoClassDefFoundError: com/ibatis/sqlmap/engine/mapping/result/BasicResultMap at ...
- Camera2Raw
This sample demonstrates how to use the Camera2 API to capture RAW camera buffers and save them as D ...
- 【IOS】 XML解析和xml转plist文件(GDataXML)
iOS对于XML的解析有系统自带的SDK--NSXMLParser,鄙人愚拙,只会用GDataXML进行解析,这里仅介绍GData的使用.(以下图为例) 1.对于一个xml文件,先读取出来 NSDat ...
- centos7 部署ssserver
centos7 部署shadowsocks服务端 为什么要选centos7? 以后centos7 肯定是主流,在不重要的环境还是尽量使用新系统吧 centos7 的坑 默认可能会有firewall 或 ...
- 查看Oracle数据库被锁住的表,删除锁表的进程
锁表处理及查询 查看Oracle数据库被锁住的表,删除锁表的进程 1.查看被锁住的表 SELECT dob.object_name table_name, lo.locked_mode, lo. ...
- JavaScript--DOM增删改操作
JavaScript使用DOM操作节点来进行增删改操作 <!DOCTYPE html> <html> <head> <meta charset="U ...
- left ,right ,cross ,full/left outer join/区别 详解
--创建测试表wwif OBJECT_ID('qq') is not null drop table qqcreate table qq([序号] varchar(5),[内容1] varchar(1 ...
- Wpf ListBox数据绑定实例1--绑定字典集合
1.使用ListBox绑定Dictionary字典数据 ListBox常用事件SelectionChanged private void bindListBox() { Dictionary<s ...
- HTML5 离线缓存详解(转)
离线缓存是html5新特性之一,简单理解就是第一次加载后将数据缓存,在没有清除缓存前提下,下一次没有网络也可以加载,用在静态数据的网页或游戏比较好用.当然,Html5新的特性都不是所有浏览器都能支持的 ...