以后做双精题请至少先跑个数据。。。输入都不一样。。。

做法就是离散化大力线段树。

记得在x+1和y-1插点 看这个数据:

1000 12
1 100
50 80
80 99
50 98
1 56
100 200
200 300
300 500
500 600
600 1000
260 560
160 580

输出7(自己yy吧yy不了网上大把题解)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std; int n,m;
struct query
{
int x,y;
}q[];
int lslen,ls[];
void LSH()
{
lslen=;
for(int i=;i<=m;i++)
{
ls[++lslen]=q[i].x,ls[++lslen]=q[i].y;
if(q[i].x+<q[i].y)
ls[++lslen]=q[i].x+,ls[++lslen]=q[i].y-;
}
ls[++lslen]=n;
sort(ls+,ls+lslen+); lslen=unique(ls+,ls+lslen+)-ls-;
for(int i=;i<=m;i++)
q[i].x=lower_bound(ls+,ls+lslen+,q[i].x)-ls,
q[i].y=lower_bound(ls+,ls+lslen+,q[i].y)-ls;
n=lower_bound(ls+,ls+lslen+,n)-ls;
} struct trnode
{
int l,r,lc,rc,c;
}tr[];int trlen;
void bt(int l,int r)
{
int now=++trlen;
tr[now].l=l;tr[now].r=r;tr[now].c=-;
tr[now].lc=tr[now].rc=-;
if(l<r)
{
int mid=(l+r)/;
tr[now].lc=trlen+;bt(l,mid);
tr[now].rc=trlen+;bt(mid+,r);
}
}
void change(int now,int l,int r,int k)
{
if(tr[now].l==l&&tr[now].r==r){tr[now].c=k;return ;} int mid=(tr[now].l+tr[now].r)/;
int lc=tr[now].lc,rc=tr[now].rc; if(tr[now].c!=-)
{
tr[lc].c=tr[now].c;
tr[rc].c=tr[now].c;
} if(r<=mid) change(lc,l,r,k);
else if(mid+<=l)change(rc,l,r,k);
else change(lc,l,mid,k), change(rc,mid+,r,k); if(tr[lc].c==tr[rc].c)tr[now].c=tr[lc].c;
else tr[now].c=-;
}
bool col[];
void findans(int now,int l,int r)
{
if(tr[now].c!=-){col[tr[now].c]=true;return ;}
if(l==r)return ; int mid=(tr[now].l+tr[now].r)/;
int lc=tr[now].lc,rc=tr[now].rc; if(r<=mid) findans(lc,l,r);
else if(mid+<=l)findans(rc,l,r);
else findans(lc,l,mid),findans(rc,mid+,r);
}
int main()
{
n=1e7;scanf("%d",&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&q[i].x,&q[i].y);
if(q[i].x>n)i--,m--;
if(q[i].y>n)q[i].y=n;
}
LSH(); trlen=;bt(,n);
for(int i=;i<=m;i++)change(,q[i].x,q[i].y,i); memset(col,false,sizeof(col));
findans(,,n);
int ans=;
for(int i=;i<=m;i++)
if(col[i]==true)ans++;
printf("%d\n",ans);
return ;
}

bzoj5029: 贴小广告&&bzoj5168: [HAOI2014]贴海报的更多相关文章

  1. BZOJ5029: 贴小广告 & BZOJ5168: [HAOI2014]贴海报

    [传送门:BZOJ5029&BZOJ5168] 简要题意: 给出m段区间l[i],r[i],表示l[i]到r[i]的数全部变成i,求出最后有多少种不同的数 题解: 线段树+离散化 这是一道经典 ...

  2. bzoj5029 贴小广告

    Description 现在有一堵墙,墙上分为若干个单元.接下来会来n个人在墙上贴小广告.每次每个人选择墙上连续一段的单元贴上自己公司与众不同的小广告.因为小广告可能会出现被覆盖的情况,由于公司之间存 ...

  3. BZOJ5168: [HAOI2014]贴海报 线段树

    Description Bytetown城市要进行市长竞选,所有的选民可以畅所欲言地对竞选市长的候选人发表言论.为了统一管理,城市委 员 会为选民准备了一个张贴海报的electoral墙.张贴规则如下 ...

  4. 从运营商小广告到HTTPS

    相信很多人都试过这样的经历,浏览一个正常的网站时,右下突然角弹出一堆小广告,而且这些广告的内容和你浏览的网站格格不入: 前几天还有某微博用户爆料访问github时居然也有广告: 又或者,你有没有试过因 ...

  5. 【题解】Luogu P3740 [HAOI2014]贴海报

    woc,今天已经是day -1了 再写一颗珂朵莉树来++rp吧 否则就要AFO了qaq 这有可能是我最后一篇题解/博客qaq 原题传送门:P3740 [HAOI2014]贴海报 考前刷水题到底是对还是 ...

  6. 1682. [HAOI2014]贴海报

    1682. [HAOI2014]贴海报 ★★☆   输入文件:ha14d.in   输出文件:ha14d.out   简单对比 时间限制:1 s   内存限制:256 MB [题目描述] Byteto ...

  7. PJzhang:关闭wps小广告和快速关闭445端口

    猫宁!!! ​​   kali linux上安装的wps,没有广告,而且轻巧简洁.   如果你在windows上安装wps,除了ppt.word.excel,还会有一个h5的应用,当然,最令人烦扰的当 ...

  8. cogs1682. [HAOI2014]贴海报 x

    1682. [HAOI2014]贴海报 ★★☆   输入文件:ha14d.in   输出文件:ha14d.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] Bytetow ...

  9. 淘宝小广告的鼠标移上实现html, JavaScript代码

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. 5.13redis的相关基础

    二.Redis(NoSql)  Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库,官方提供测试数据,50个并发执行 100000个请求,读的速度是110000次/s,写的速 ...

  2. Asp.net MVC4 Step by Step (2)-参数数据的传递

    首先创建一个表单,不同于WebForm,框架提供了一系列HMTL帮助方法来生成HTML标签. 下面创建一个Create.cshtml为文件名的视图. <h2> Create Auction ...

  3. python--3、 可迭代对象、迭代器、生成器

    可迭代对象 iterable 可直接作用于for循环的对象统称为可迭代对象. 有 list. dict.tuple.set.str等数据类型,还有 generator(包括生成器和带yield的gen ...

  4. ArrayList 源码

    1.ArrayList的类关系: 2.属性及方法      2.1 构造           三个构造方法分别对应:                通过传入初始化容器大小构造数组列表         ...

  5. C# 彻底关闭程序,包括循环

    System.Environment.Exit(System.Environment.ExitCode); this.Dispose(); this.Close();

  6. (转)Arcgis for Js之GeometryService实现测量距离和面积

    http://blog.csdn.net/gisshixisheng/article/details/40540601 距离和面积的测量时GIS常见的功能,在本节,讲述的是通过GeometryServ ...

  7. Uoj #274. 【清华集训2016】温暖会指引我们前行 LCT维护边权_动态最小生成树

    Code: 行#include<bits/stdc++.h> #define ll long long #define maxn 1000000 #define inf 100000000 ...

  8. Docker 导入镜像报错:open /var/lib/docker/tmp/docker-import-743441288/redis-3.0.7/json: no such file or directory

    下载好了redis的tar包,然后导入redis镜像是报错open /var/lib/docker/tmp/docker-import-743441288/redis-3.0.7/json: no s ...

  9. Got permission denied while trying to connect to the Docker daemon socket at unix

    拉取Dockerimages时错误信息如下: [master@localhost ~]$ docker pull redis Using default tag: latest Got permiss ...

  10. UI Testing

    UI Test能帮助我们去验证一些UI元素的属性和状态.Apple 在 Xcode 7 中新加入了一套 UI Testing 的工具,其目的就是解决自动化UI测试这个问题.新的 UI Testing ...