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的更多相关文章

  1. Poj 2528-Mayor's posters 线段切割

      题目:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total ...

  2. POJ - 2528Mayor's posters (离散化+线段树区间覆盖)

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

  3. POJ 2528 Mayor's posters

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  4. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  5. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

  6. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 ...

  7. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  8. POJ 2528 - Mayor's posters - [离散化+区间修改线段树]

    题目链接:http://poj.org/problem?id=2528 Time Limit: 1000MS Memory Limit: 65536K Description The citizens ...

  9. POJ:2528(Mayor's posters)离散化成段更新+简单哈希

    http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that the ca ...

随机推荐

  1. 解决拼团首页swiper组件手动轮播卡顿问题

    解决 swiper lag , 可能是渲染背景backface-visibility后导致卡顿吧! //以下代码添加到.swiper-wrapper中 -webkit-perspective: 300 ...

  2. ios使用openUrl进行应用跳转

    1.拨打电话: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://68979"]]; ...

  3. VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号

    以下代码可以取得系统特征码(网卡MAC.硬盘序列号.CPU ID.BIOS编号) BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码 UINT uSys ...

  4. google(转帖)

    本帖最后由 qiushui_007 于 2014-6-10 16:14 编辑 IP Addresses of Google Global Cachewww.kookle.co.nr Bulgaria  ...

  5. POJ 1011 sticks 搜索

    Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 125918   Accepted: 29372 Descrip ...

  6. Android Xutils 框架

    XUtils是git上比较活跃 功能比较完善的一个框架,是基于afinal开发的,比afinal稳定性提高了不少,下面是介绍: 鉴于大家的热情,我又写了一篇Android 最火框架XUtils之注解机 ...

  7. codevs2059逃出克隆岛(传送门bfs)

    /* 和普通的迷宫问题类似只是多了一个叫传送门的东西 对于传送门的处理: 每当跑到传送门就把其余所有传送门周围的点都入队 传送门之间不花费时间并且从不是传送门的点走到传送门 也不花费时间花费时间的(好 ...

  8. Datables wrning(table id='example'):Cannot reinitialise DataTable.

    出现的问题如下所示: Datables wrning(table id='example' Datables object for this table,please pass eithser no ...

  9. 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序(Oledb)

    转载:http://blog.csdn.net/lemontec/article/details/1754413 前几天用c#读 Excel 出现了如下问题未在本地计算机上注册“Microsoft.J ...

  10. MIME协议

    转:http://blog.csdn.net/flfna/article/details/5048290 MIME类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候 ...