hiho1079 线段树区间改动离散化
题目链接:
代码:
#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 线段树区间改动离散化的更多相关文章
- POJ-2528 Mayor's posters (线段树区间更新+离散化)
题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- poj2528(线段树区间替换&离散化)
题目链接: http://poj.org/problem?id=2528 题意: 第一行输入一个 t 表 t 组输入, 对于每组输入: 第一行 n 表接下来有 n 行形如 l, r 的输入, 表在区 ...
- poj 2528 线段树区间修改+离散化
Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...
- POJ-2528 Mayor's posters(线段树区间更新+离散化)
http://poj.org/problem?id=2528 https://www.luogu.org/problem/UVA10587 Description The citizens of By ...
- LightOJ 1089 - Points in Segments (II) 线段树区间修改+离散化
http://www.lightoj.com/volume_showproblem.php?problem=1089 题意:给出许多区间,查询某个点所在的区间个数 思路:线段树,由于给出的是区间,查询 ...
- POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...
- POJ 2528 Mayor's posters(线段树/区间更新 离散化)
题目链接: 传送门 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of By ...
随机推荐
- ssh执行远程服务器脚本 提示php: command not found
ssh执行远程服务器脚本 提示php: command not found 设置环境变量 一台机器作为管理机,来管理其他服务器,并通过key认证,免密码登陆的. 在管理机上通过ssh登陆到其他服务器来 ...
- 学习笔记6——插件 API,“过滤器”(Filters)和“动作”(Actions)
WordPress 中有一种叫执行挂勾的机制,允许插件把一些功能“挂载”到 WordPress 当中.也就是说,在系统运行至某一个环节时,去调用插件内的一些函数.执行挂勾分为两种: 动作 (Actio ...
- Luogu【P2065】贪心的果农(DP)
题目链接 几乎所有DP题目前本蒟蒻都没有思路.当然包括但不限于这道题.每次都是看了题解然后打的(等价于抄题解)很羞耻 这道题经思考发现,越靠前砍的果树长果子的能力一定越弱,如果长果子的能力一样弱就先把 ...
- BZOJ-1269 文本编辑器
.... 这道题就是Noi原题嘛...虽然更容易写... 题意: 建立一个数据结构,并支持以下操作: Insert 区间插入有序序列:Delete 区间删除:Rotate 区间翻转:Get 单点查询 ...
- 刷题总结——烽火传递(单调队列+dp)
题目: 题目描述 烽火台又称烽燧,是重要的防御设施,一般建在险要处或交通要道上.一旦有敌情发生,白天燃烧柴草,通过浓烟表达信息:夜晚燃烧干柴,以火光传递军情.在某两座城市之间有 n 个烽火台,每个烽火 ...
- 【二叉树】hdu 1710 Binary Tree Traversals
acm.hdu.edu.cn/showproblem.php?pid=1710 [题意] 给定一棵二叉树的前序遍历和中序遍历,输出后序遍历 [思路] 根据前序遍历和中序遍历递归建树,再后续遍历输出 m ...
- C 语言中的 feof()函数
功能: feof 是 C 语言标准库函数函数,其原型在 stdio.h 中,其功能是检测流上的文件结束符,如果文件结束,则返回非0值,否则返回0,文件结束符只能被 clearerr() 清除. 用法: ...
- 使用反射获取类中的属性(可用于动态返回PO类的列,当做表格的表头)
//利用反射取类中的属性字段 try { Class clazz = Class.forName("houji.bean.model.TaskModel"); Field[] fi ...
- Failed building wheel for Twisted
在安装scrapy框架的过程中,pip install scrapy 出现报错信息: building 'twisted.test.raiser' extension error: Microsoft ...
- 思维定势--AtCoder Regular Contest 092 D - Two Sequences
$n \leq 100000$的俩序列,数字范围$2^{28}$,问所有$a_i+b_j$的$n^2$个数字的异或和. 这种东西肯定是按位考虑嘛,从低位开始然后补上进位.比如说第一位俩串分别有$c$个 ...