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网络服务第六章PXE高效能批量网络装机

    1.IP地址配置 2.关闭防火墙以及selinux状态如下 systemctl  stop     firewalld Iptables -F Setenforce 0 三.部署FTP服务 1.安装F ...

  2. 还在写CURD?试试这款基于mybatis-plus的springboot代码生成器

    目录 ⚡Introduction ✔️Release Features Quick Start Examples 1.Controller模板代码示例 2.Service模板代码示例 3.Servic ...

  3. 《Splunk智能运维实战》——1.7 为本书加载样本数据

    本节书摘来自华章计算机<Splunk智能运维实战>一书中的第1章,第1.7节,作者 [美]乔史·戴昆(Josh Diakun),保罗R.约翰逊(Paul R. Johnson),德莱克·默 ...

  4. SVN签出,回退

    2019独角兽企业重金招聘Python工程师标准>>> yum install -y subversion 安装SVN 签出代码 : [root@test svn]# svn che ...

  5. 洛谷 P1816 忠诚 ST函数

    题目描述 老管家是一个聪明能干的人.他为财主工作了整整10年,财主为了让自已账目更加清楚.要求管家每天记k次账,由于管家聪明能干,因而管家总是让财主十分满意.但是由于一些人的挑拨,财主还是对管家产生了 ...

  6. muduo网络库源码学习————线程特定数据

    muduo库线程特定数据源码文件为ThreadLocal.h //线程本地存储 // Use of this source code is governed by a BSD-style licens ...

  7. 虚拟化云计算平台Proxmox VE

    1.虚拟化技术介绍 1.1.OpenVZ 简介 OpenVZ 是开源软件, 是基于Linux平台的操作系统级服务器虚拟化解决方案,它是基于Linux内核和作业系统的操作系统级虚拟化技术. OpenVZ ...

  8. speedtest 测试服务器上传下载速度

    下载speedtest.py wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py 赋予执行权限 ...

  9. mysql-case..when知识点总结

    case...when..有两种语法: 第一种: case  case_value when when_value  then statement_list [when when_value  the ...

  10. Spring AOP概述

    一.AOP的基本概念: 首先先给出一段比较专业的术语: 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的 ...