E. Physical Education Lessons
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson!

Since Alex doesn't want to get expelled, he wants to know the number of working days left until the end of the term, so he can attend physical education lessons during these days. But in BSU calculating the number of working days is a complicated matter:

There are n days left before the end of the term (numbered from 1 to n), and initially all of them are working days. Then the university staff sequentially publishes q orders, one after another. Each order is characterised by three numbers l, r and k:

  • If k = 1, then all days from l to r (inclusive) become non-working days. If some of these days are made working days by some previous order, then these days still become non-working days;
  • If k = 2, then all days from l to r (inclusive) become working days. If some of these days are made non-working days by some previous order, then these days still become working days.

Help Alex to determine the number of working days left after each order!

Input

The first line contains one integer n, and the second line — one integer q (1 ≤ n ≤ 109, 1 ≤ q ≤ 3·105) — the number of days left before the end of the term, and the number of orders, respectively.

Then q lines follow, i-th line containing three integers li, ri and ki representing i-th order (1 ≤ li ≤ ri ≤ n, 1 ≤ ki ≤ 2).

Output

Print q integers. i-th of them must be equal to the number of working days left until the end of the term after the first i orders are published.

Example
Input
4
6
1 2 1
3 4 1
2 3 2
1 3 2
2 4 1
1 4 2
Output
2
0
2
3
1
4
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int rt=,LL[N],RR[N],V[N],tot=,lazy[N];
void pdw(int x,int val){
if(lazy[x]!=-) {
if(!LL[x]) LL[x]=++tot;if(!RR[x]) RR[x]=++tot;
if(lazy[x]) V[LL[x]]=(val+)/,V[RR[x]]=val/;
else V[LL[x]]=V[RR[x]]=;
lazy[LL[x]]=lazy[RR[x]]=lazy[x];
lazy[x]=-;
}
}
void update(int &x,int l,int r,int L,int R,bool f){
if(!x) x=++tot;
if(L>=l&&R<=r) {
if(f) V[x]=R-L+;else V[x]=;
lazy[x]=f;
return;
}
pdw(x,R-L+);
int mid=(L+R)>>;
if(l<=mid) update(LL[x],l,r,L,mid,f);
if(r>mid) update(RR[x],l,r,mid+,R,f);
V[x]=V[LL[x]]+V[RR[x]];
}
int main(){
int n,m,x,y,z;
scanf("%d%d",&n,&m);
memset(lazy,-,sizeof(lazy));
for(int i=;i<=m;++i) {
scanf("%d%d%d",&x,&y,&z);
update(rt,x,y,,n,z==);
printf("%d\n",n-V[]);
}
}

set做法

离散化线段树做法

E. Physical Education Lessons 动态开辟线段树区间更新的更多相关文章

  1. F. Pathwalks动态开辟线段树

    题意:n点m边,然后要求走最多的路,走路的时候经过的边权必须是严格递增. 解法1:传统的区间更新 解法2:发现区间更新只是对两个固定的点所延长形成的区间段,所以问题可以退化成单点更新单点查询. 然后动 ...

  2. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  3. hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新

    #1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...

  4. HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...

  5. HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...

  6. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

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

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

  8. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

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

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

随机推荐

  1. 【linux题目】第三关

    1. 解释下什么是GPL,GNU,自由软件? 2. 如何选择Linux操作系统版本? 3. 安装系统时如何给Linux操作系统分区? 4. 描述Linux系统的启动过程? 5. 简要说出20个Linu ...

  2. 解析HTML、JS与PHP之间的数据传输

    在电商网站搭建过程中,前端经常会向后端请求数据,有时候通过HTML.JS和PHP文件的处理来实现数据的连通.通常情况下,用户在HTML中做关键字操作,JS对提交的表单进行数据处理,向后端发起ajax请 ...

  3. 初入React源码(一)

    导语 React是我接触的第二个框架,我最初开始接触的是vue,但是并没有深入的理解过vue,然后在工作过程中,我开始使用了React,现在已经觉得React会比vue更加实用,但是这只是个人观点,可 ...

  4. 使用react脚手架create-react-app创建react应用

    Create React App是一种官方支持的创建单页React应用程序的方法.它提供了一个没有配置的现代构建设置. 一.全局安装脚手架: npm install -g create-react-a ...

  5. CodeForces - 262B

    Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has g ...

  6. tar命令基本、进阶使用指北

    tar命令基本.进阶使用指北 摘要 打包与压缩是我们在计算机系统日常使用中必备的一个工具,就如我们在使用Windows系统,也需要类似WinRAR的压缩软件来将许多数据.文件打包成一个文件,并压缩其占 ...

  7. IIS 搭网站(一)

    搭建类型win+IIs+asp+access(一) 第一步首先保证虚拟机的系统软盘是连接状态,如下图状态即可 第二步: 第三步: 第四步: 第五步: 第六步:这个时候就会自动搜索软盘里面的数据自动安装 ...

  8. 题目分享E 二代目

    题意:一棵点数为n的树,每个节点有点权,要求在树中中找到一个最小的x,使得存在一个点满足max(该点点权,该点相邻的点的点权+1,其他点的点权+2)=x 分析:首先要能把题目转化为上述题意 首先题目让 ...

  9. 跟哥一起学python(4)- 数据类型之Number

    本节我们开始学习python的数据类型. 什么是数据类型呢?前面我们提过,所谓的编程,就是控制一系列的数据去完成我们预设的逻辑或者功能.所以,编程语言首先要定义一系列对“数据”的处理规则.这些处理规则 ...

  10. 进程间通信之socketpair

    socketpair是进程间通信的一种方式. API: ]); DEMO: #include <stdio.h> #include <stdlib.h> #include &l ...