题目描述

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 nn days left before the end of the term (numbered from 11 to nn ), and initially all of them are working days. Then the university staff sequentially publishes qq orders, one after another. Each order is characterised by three numbers ll , rr and kk :

  • If k=1k=1 , then all days from ll to rr (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=2k=2 , then all days from ll to rr (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!

输入输出格式

输入格式:

The first line contains one integer nn , and the second line — one integer qq ( 1<=n<=10^{9}1<=n<=109 , 1<=q<=3·10^{5}1<=q<=3⋅105) — the number of days left before the end of the term, and the number of orders, respectively.

Then qq lines follow, ii -th line containing three integers l_{i}li​ , r_{i}ri​ and k_{i}ki​ representing ii -th order ( 1<=l_{i}<=r_{i}<=n1<=li​<=ri​<=n , 1<=k_{i}<=21<=ki​<=2 ).

输出格式:

Print qq integers. ii -th of them must be equal to the number of working days left until the end of the term after the first iiorders are published.

输入输出样例

输入样例#1:

4
6
1 2 1
3 4 1
2 3 2
1 3 2
2 4 1
1 4 2
输出样例#1:

2
0
2
3
1
4 下午去湘江边的橘子洲van了一圈,然而明天就要去雅礼报道了hhhh 很明显n<=10^9肯定不能用普通的线段树做,虽然可能离散化完了之后会有奇淫技巧能做。。。。
但是我首先想到的是动态开点直接打标机下传、、、毕竟线段树一次操作涉及的节点数是log n级别的,就算是区间操作+需要标记下传的话,
需要的空间也只是常数大了大,复杂度依然是log n的,而且很多操作还会有重复的区间呢。 于是我就动态开点+线段树打tag瞎做了做,,,本地垃圾笔记本3s才能过极端数据,,,,不过codeforces的评测机跑的飞快,硬生生的缩成了300+ms。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define maxn 200005
using namespace std;
struct node{
int lc,rc;
int tag,sum;
}nil[maxn*];
int n,le,ri,tot;
int q,opt,cnt=; inline void work(int v,int tmp,int len){
if(tmp==-) nil[v].tag=-,nil[v].sum=;
else nil[v].tag=,nil[v].sum=len;
} inline void pushdown(int o,int l,int r){
int ls=nil[o].lc,rs=nil[o].rc,mid=l+r>>;
if(nil[o].tag==-){
nil[o].tag=;
work(ls,-,mid-l+);
work(rs,-,r-mid);
}
else if(nil[o].tag==){
nil[o].tag=;
work(ls,,mid-l+);
work(rs,,r-mid);
}
} void update(int u,int l,int r){
if(l>=le&&r<=ri){
int pre=nil[u].sum;
work(u,opt,r-l+);
tot+=nil[u].sum-pre;
return;
}
if(!nil[u].lc) nil[u].lc=++cnt;
if(!nil[u].rc) nil[u].rc=++cnt;
pushdown(u,l,r); int mid=l+r>>;
if(le<=mid) update(nil[u].lc,l,mid);
if(ri>mid) update(nil[u].rc,mid+,r); nil[u].sum=nil[nil[u].lc].sum+nil[nil[u].rc].sum;
} int main(){
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout); int root=;
nil[]=(node){,,,};
scanf("%d%d",&n,&q);
while(q--){
scanf("%d%d%d",&le,&ri,&opt);
opt=(opt==?-:);
update(root,,n);
printf("%d\n",n-tot);
} return ;
}

Codeforces 915 E Physical Education Lessons的更多相关文章

  1. 【CodeForces】915 E. Physical Education Lessons 线段树

    [题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...

  2. 【Codeforces 915E】 Physical Education Lessons

    [题目链接] 点击打开链接 [算法] 线段树,注意数据量大,要动态开点 [代码] #include<bits/stdc++.h> using namespace std; ; ,root ...

  3. Codeforces 915E Physical Education Lessons

    原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...

  4. Physical Education Lessons CodeForces - 915E (动态开点线段树)

    Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...

  5. Codeforces 915E. Physical Education Lessons(动态开点线段树)

    E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...

  6. CF915E Physical Education Lessons 动态开点线段树

    题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...

  7. 【题解】Luogu CF915E Physical Education Lessons

    原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...

  8. CF915E Physical Education Lessons

    题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...

  9. 线段树 离散化 E. Infinite Inversions E. Physical Education Lessons

    题目一:E. Infinite Inversions 这个题目没什么思维量,还比较简单,就是离散化要加上每一个值的后面一个值,然后每一个值放进去的不是1 ,而是这个值与下一个点的差值. 因为这个数代表 ...

随机推荐

  1. 创建 React 项目

    依次输入命令: npm install -g create-react-app create-react-app react16 cd my-app npm start 在浏览器中输入 local:3 ...

  2. HDU 4334 Trouble (数组合并)

    Trouble Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. python判断操作系统

    https://www.crifan.com/python_get_current_system_os_type_and_version_info/ 参考:https://stackoverflow. ...

  4. [Leetcode Week9]Minimum Path Sum

    Minimum Path Sum 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/minimum-path-sum/description/ Descr ...

  5. 【C语言】一次内存泄露的分析的记录

    今天运行一个程序,程序刚启动时占用内存很小,在运行过程中发现占用的内存会一直增大. 用cat /proc/pid/statm的方式查看发现也确实在一直增大. 而且这个程序移植到另外一个平台后,会直接无 ...

  6. 【bzoj3439】KPM的MC密码

    这题乍一看后缀相等很烦的样子…… 其实如果把字符串倒过来,那么相等的后缀就可以转化成前缀,前缀相等扔进trie就可以了. 剩下无非是Trie的树链kth,主席树随便维护就好. 注意一个串彻底结束才能打 ...

  7. Mac-sublime text 3破解版

    在史蒂芬周下载破解版 安装package control import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f ...

  8. spring boot jar 进程自动停止,自动终止,不能后台持续运行

    第一次部署spring boot 到linux上,用命令java -jar **.jar,发现应用自动退出,进程停止了.后来发现要不挂断的执行命令,忽略所有的挂断信号,用以下命令解决 nohup ja ...

  9. net core服务器缺包,如何在线安装?

    Install -package命令不行. 下面命令也不行.求助大家,怎么安装?

  10. Selenium2+python自动化61-Chrome浏览器(chromedriver)【转载】

    前言 selenium2启动Chrome浏览器是需要安装驱动包的,但是不同的Chrome浏览器版本号,对应的驱动文件版本号又不一样,如果版本号不匹配,是没法启动起来的. 一.Chrome遇到问题 1. ...