题目描述

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. [NOI2003] 文本编辑器 (splay)

    复制炸格式了,就不贴题面了 [NOI2003] 文本编辑器 Solution 对于光标的移动,我们只要记录一下现在在哪里就可以了 Insert操作:手动维护中序遍历结果,即每次取中点像线段树一样一样递 ...

  2. POJ2559 Largest Rectangle in a Histogram (单调栈

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26012 ...

  3. 7月20号day12总结

    今天学习过程和小结 先进行了复习,主要 1,hive导入数据的方式有 本地导入  load data [local] inpath 'hdfs-dir' into table tablename; s ...

  4. (转)HTTP请求中URL地址的编码和解码

    HTTP请求中,类似   http%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml%2Fv3Jump.html  的地址 如何解码成    http://www ...

  5. HDU 4320 Arcane Numbers 1 (数论)

    A - Arcane Numbers 1 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  6. django中管理程序1

    为了解决启动关闭程序方便,在django中启动结束任务的问题. urls.py ################DJANGO start kill job####################### ...

  7. 【Mysql优化】索引优化策略

    1:索引类型 1.1 B-tree索引 注: 名叫btree索引,大的方面看,都用的平衡树,但具体的实现上, 各引擎稍有不同, 比如,严格的说,NDB引擎,使用的是T-tree   Myisam,in ...

  8. elastaticsearch

    # https://elasticsearch-dsl.readthedocs.io/en/latest/ # 文档:https://es.xiaoleilu.com/054_Query_DSL/70 ...

  9. shell命令行混合进制计算器smartbc

    需要简单的计算的时候,不想用GUI的计算器,能在shell下直接计算就最好了 查了下,有个东西叫 bc,  具体的使用就不赘述了,可以运行bc,然后进去计算,也可以echo传递过去,大概是像这样 ec ...

  10. (十二)进一步掌握STVD/COSMIC

    如何分配变量到指定的地址 举例:unsigned char temp_A@0x00; //定义无符号变量temp_A,强制其地址为0x00unsigned char temp_B@0x100; //定 ...