题目链接:

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. VC调试入门

    概述调试是一个程序员最基本的技能,其重要性甚至超过学习一门语言.不会调试的程序员就意味着他即使会一门语言,却不能编制出任何好的软件.这里我简要的根据自己的经验列出调试中比较常用的技巧,希望对大家有用. ...

  2. Matplotlib绘图属性(1)

    [matplotlib颜色.形状.线型等详细配置方法] #1.颜色(三种方法)-color 八种内置颜色及其缩写: b:blue <蓝色> c:cyan <青色> g:gree ...

  3. web项目架构

  4. RESTful API接口

    我所理解的RESTful Web API [设计篇] 百度:RESTful restful一种软件架构风格.设计风格,而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件 ...

  5. ajax dome案例

    一.首先HTML页面 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  6. 安卓ImageView.src设置图片拉伸、填满控件的方法

    代码改变世界 安卓ImageView.src设置图片拉伸.填满控件的方法 需要给你的ImageView布局加上Android:adjustViewBounds="true"

  7. 【Android】监听viewpager子页面里面的Button按钮

    最近做项目遇到Viewpager+Fragment滑动页面,要监听子页面中的按钮,在网上查了些解决办法: 办法一: 这种方法是在适配器初始化中进行监听,有人亲测通过,但是我继承FragmentPage ...

  8. hdu6071[最短路+解不等式] 2017多校4

    求出所有,从2走到x所需的花费在对 t = 2*min(d1,2, d2,3) 模运算下,  所有剩余系的最短路即可(把一个点拆成 t 个点, 每个点代表一种剩余系), 知道了所有剩余系就可以凑出答案 ...

  9. 【2018.10.1】「JOI 2014 Final」年轮蛋糕

    题面 一看到求“最小值的最大值”这种问题,就能想到二分了. 二分答案,然后我们要把一圈分成三块,使这三块的大小都$\geq mid$.做法是把环展开成2倍长度的链,先钦定一个起点,然后根据前缀和再二分 ...

  10. Redis对象的设计与实现

    一.Redis对象结构Redis中的每个对象都由一个redisObject结构表示: typedef struct redisObject { unsigned type;//类型 unsigned ...