题目链接:

hihocoder1079

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 100050
using namespace std;
int cnt[maxn<<1];
int v[maxn<<2];
int vis[maxn<<2]={0};
int modify[maxn][2];
int ans=0;
void travel(int l,int r,int rt)
{
if(v[rt])
{
if(!vis[v[rt]])
vis[v[rt]]=1,ans++;
return;
}
if(l==r)
return;
int m=(l+r)>>1;
travel(lson);
travel(rson);
}
void update(int L,int R,int w,int l,int r,int rt)
{
if(L<=l&&R>=r)
{
v[rt]=w;
return;
}
if(v[rt])
{
v[rt<<1|1]=v[rt<<1]=v[rt];
v[rt]=0;
}
int m=(l+r)>>1;
if(L<=m)
update(L,R,w,lson);
if(R>m)
update(L,R,w,rson);
}
int main()
{
// freopen("in.txt","r",stdin);
int d,n,a,b,s=0;
scanf("%d%d",&d,&n);
for(int i=1; i<=d; i++)
{
scanf("%d%d",&modify[i][0],&modify[i][1]);
cnt[s++]=modify[i][0];
cnt[s++]=modify[i][1];
}
sort(cnt,cnt+s);
s=unique(cnt,cnt+s)-cnt;
for(int i=1; i<=d; i++)
{
a=lower_bound(cnt,cnt+s,modify[i][0])-cnt+1; // x~x+1 才代表线段树中的一个点
b=lower_bound(cnt,cnt+s,modify[i][1])-cnt;
update(a,b,i,1,s,1);
}
travel(1,s,1);
printf("%d\n",ans);
return 0;
}

hiho1079 线段树区间改动离散化的更多相关文章

  1. POJ-2528 Mayor's posters (线段树区间更新+离散化)

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  2. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  3. POJ2528:Mayor's posters(线段树区间更新+离散化)

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

  4. poj2528(线段树区间替换&离散化)

    题目链接: http://poj.org/problem?id=2528 题意: 第一行输入一个 t 表 t 组输入, 对于每组输入: 第一行  n 表接下来有 n 行形如 l, r 的输入, 表在区 ...

  5. poj 2528 线段树区间修改+离散化

    Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...

  6. POJ-2528 Mayor's posters(线段树区间更新+离散化)

    http://poj.org/problem?id=2528 https://www.luogu.org/problem/UVA10587 Description The citizens of By ...

  7. LightOJ 1089 - Points in Segments (II) 线段树区间修改+离散化

    http://www.lightoj.com/volume_showproblem.php?problem=1089 题意:给出许多区间,查询某个点所在的区间个数 思路:线段树,由于给出的是区间,查询 ...

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

    题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...

  9. POJ 2528 Mayor's posters(线段树/区间更新 离散化)

    题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of By ...

随机推荐

  1. Java程序员---技能树

    计算机基础: 比如网络相关的知识. 其中就包含了 TCP 协议,它和 UDP 的差异.需要理解 TCP 三次握手的含义,拆.粘包等问题. 当然上层最常见的 HTTP 也需要了解,甚至是熟悉. 这块推荐 ...

  2. 优化代码,引发了早期缺陷导致新bug

    早期系统有个缺陷,调用js时少提交一个参数,导致该参数一直是undefined,但是不会引起bug. 对系统进行优化后,这个参数变成了必要的,然后代码一直会走else,undefined值明显不是一个 ...

  3. 安卓Toast实现

    代码改变世界 Toast实现显示 // 第一个参数:当前的上下文环境.可用getApplicationContext()或this // 第二个参数:要显示的字符串.也可是R.string中字符串ID ...

  4. BZOJ 2300 [HAOI2011]防线修建 ——计算几何

    只需要倒着插入,然后维护一个凸包就可以了. 可以用来学习set的用法 #include <map> #include <set> #include <cmath> ...

  5. 【扫描线或树状数组】CSU 1335 高桥和低桥

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1335 [题意] 给定n座桥的高度,给定m次洪水每次的涨水水位ai和退水水位bi 询问有多少座桥 ...

  6. poj 2891 模线性方程组求解

    Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 8005   ...

  7. 【HDOJ6354】Everything Has Changed(计算几何)

    题意: 给定一个平面和一个(0,0)为中心的大圆,有n个小圆保证没有两两之间相交与覆盖整个大圆的情况,求小圆覆盖后大圆的周长并 1≤m≤100, -1e3<=x[i],y[i]<=1e3, ...

  8. hdu 4951

    Multiplication table Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. 【Android】状态栏通知Notification、NotificationManager详解(转)

    在Android系统中,发一个状态栏通知还是很方便的.下面我们就来看一下,怎么发送状态栏通知,状态栏通知又有哪些参数可以设置? 首先,发送一个状态栏通知必须用到两个类:  NotificationMa ...

  10. SGU103+POJ 1158 最短路/dp

    题意:一个无向图,求起点到终点最少时间,限制:每个路口有灯,要灯颜色一样才能过去,灯之有俩种颜色,周期 变化,给定每个灯初态,时间. 思路:开始就想到直接DP,方程dp[k]=dp[i]+distan ...