【codevs1191】数轴染色 线段树 区间修改+固定区间查询
【codevs1191】数轴染色
题目描述 Description
在一条数轴上有N个点,分别是1~N。一开始所有的点都被染成黑色。接着
我们进行M次操作,第i次操作将[Li,Ri]这些点染成白色。请输出每个操作执行后
剩余黑色点的个数。
输入描述 Input Description
输入一行为N和M。下面M行每行两个数Li、Ri
输出描述 Output Description
输出M行,为每次操作后剩余黑色点的个数。
样例输入 Sample Input
10 3
3 3
5 7
2 8
样例输出 Sample Output
9
6
3
数据范围及提示 Data Size & Hint
数据限制
对30%的数据有1<=N<=2000,1<=M<=2000
对100%数据有1<=Li<=Ri<=N<=200000,1<=M<=200000
<:SECTION id=statistics>
题解
只要tr【1】.v的结果
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//**************************************************************************************
int ans,hash[];
struct ss
{
int l,r,v;
}tr[*];
int n,m;
void build(int k,int s,int t)
{
tr[k].l=s;
tr[k].r=t;
if(s==t){
tr[k].v=;
return;
}
int mid=(s+t)>>;
build(k<<,s,mid);
build(k<<|,mid+,t);
tr[k].v=tr[k<<].v+tr[k<<|].v;
}
void update(int k,int s,int t)
{
if(tr[k].v==)return;
if(s==tr[k].l&&t==tr[k].r)
{
tr[k].v=;
return ;
}
int mid=(tr[k].l+tr[k].r)>>;
if(t<=mid) update(k<<,s,t);
else if(s>mid)update(k<<|,s,t);
else {
update(k<<,s,mid);
update(k<<|,mid+,t);
}
tr[k].v=tr[k<<].v+tr[k<<|].v;
}
int main()
{ scanf("%d%d",&n,&m);
build(,,n);
int a,b;
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
ans=;
update(,a,b);
printf("%d\n",tr[].v);
}
return ;
}
【codevs1191】数轴染色 线段树 区间修改+固定区间查询的更多相关文章
- HDU - 1698 线段树区间修改,区间查询
这就是很简单的基本的线段树的基本操作,区间修改,区间查询,对区间内部信息打上laze标记,然后维护即可. 我自己做的时候太傻逼了...把区间修改写错了,对给定区间进行修改的时候,mid取的是节点的左右 ...
- 线段树(区间修改、区间查询) HDU 1754 I Hate It
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Codeforces Round #442 (Div. 2) E Danil and a Part-time Job (dfs序加上一个线段树区间修改查询)
题意: 给出一个具有N个点的树,现在给出两种操作: 1.get x,表示询问以x作为根的子树中,1的个数. 2.pow x,表示将以x作为根的子树全部翻转(0变1,1变0). 思路:dfs序加上一个线 ...
- 题解报告:hdu 1698 Just a Hook(线段树区间修改+lazy懒标记的运用)
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...
- poj 2528 线段树区间修改+离散化
Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...
- [线段树]区间修改&区间查询问题
区间修改&区间查询问题 [引言]信息学奥赛中常见有区间操作问题,这种类型的题目一般数据规模极大,无法用简单的模拟通过,因此本篇论文将讨论关于可以实现区间修改和区间查询的一部分算法的优越与否. ...
- E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...
- HDU 4027 Can you answer these queries? (线段树区间修改查询)
描述 A lot of battleships of evil are arranged in a line before the battle. Our commander decides to u ...
- poj2528 Mayor's posters(线段树区间修改+特殊离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
随机推荐
- Struts2标签简介
Struts2标签简介 Struts2标签的优势 标签库简化了用户对标签的使用 结合OGNL使用,对于集合.对象的访问功能非常强大 提供可扩展的主题.模板支持,极大简化了视图页面的编写 不依赖任何表现 ...
- ASP.NET MVC 4 跨域
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Contro ...
- tcpdump wireshark 实用过滤表达式(针对ip、协议、端口、长度和内容) 实例介绍
tcpdump wireshark 实用过滤表达式(针对ip.协议.端口.长度和内容) 实例介绍 标签: 网络tcpdst工具windowslinux 2012-05-15 18:12 3777人阅读 ...
- motto6
当你发现自己不错的时候,要适当的给自己加点凉水,让自己知道自己离“不错”还很远.
- CSS初学
CSS作用是美化html网页.内联:body 标签里.内嵌:head标签里,可以多次重复使用.p{}:引用时,class引用.#p{}:引用时,id引用超链接的stylea:link 超链接被点前的状 ...
- 3月20,html
html,表格的练习: 1,给图片做链接<br /><img src="200712211720988_2.jpg" usemap="A" w ...
- 从客户端中检测到有潜在危险的 Request.Form 值。
使用富文本编辑器是经常会遇到这个问题,在MVC中解决方法很简单只要在对应的action上添加[ValidateInput(false)]即可
- 淘宝(阿里百川)手机客户端开发日记第三篇 SlidingPaneLayout实现侧滑菜单
需要的三个布局文件: activity_main.xml :主窗体布局 left.xml : 左侧栏目分类布局 right.xml : 右侧内容详情 需要的组件: android.support.v4 ...
- index and polymorphic
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations class CreateStars < ...
- crontab报错
$mail 选择对应的数字查看邮件 File "/opt/app/python/tv-cms-for-ch/current/scripts/sync_cms_for_ch.py", ...