题目描述

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*71];
int n,le,ri,tot;
int q,opt,cnt=1;inline void work(int v,int tmp,int len){if(tmp==-1) nil[v].tag=-1,nil[v].sum=0;else nil[v].tag=1,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>>1;if(nil[o].tag==-1){nil[o].tag=0;work(ls,-1,mid-l+1);work(rs,-1,r-mid);}else if(nil[o].tag==1){nil[o].tag=0;work(ls,1,mid-l+1);work(rs,1,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+1);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>>1;if(le<=mid) update(nil[u].lc,l,mid);if(ri>mid) update(nil[u].rc,mid+1,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=1;nil[1]=(node){0,0,0,0};scanf("%d%d",&n,&q);while(q--){scanf("%d%d%d",&le,&ri,&opt);opt=(opt==2?-1:1);update(root,1,n);printf("%d\n",n-tot);}return 0;
}

转载于:https://www.cnblogs.com/JYYHH/p/8406106.html

Codeforces 915 E Physical Education Lessons相关推荐

  1. E. Physical Education Lessons

    Physical Education Lessons 动态开点线段树 #include<bits/stdc++.h> using namespace std; #define maxn 1 ...

  2. codeforces 915E - Physical Education Lessons 动态开点线段树

    题意: 最大$10^9$的区间, $3*10^5$次区间修改,每次操作后求整个区间的和 题解: 裸的动态开点线段树,计算清楚数据范围是关键... 经过尝试 $2*10^7$会$MLE$ $10^7$会 ...

  3. 【Codeforces】53D Physical Education (有点像冒泡)

    http://codeforces.com/problemset/problem/53/D 从上面所给的序列变成下面所给的序列 交换的时候只能交换相邻的两个数字 输出每一步的交换方法,输出的是该元素在 ...

  4. CF915E Physical Education Lessons(珂朵莉树)

    中文题面 据说正解是动态开点线段树而且标记也不难下传的样子 然而这种区间推平的题目还是喜欢写珂朵莉树啊--码量小-- 虽然真要构造的话随便卡-- 1 //minamoto 2 #include< ...

  5. CF 915E. Physical Education Lessons 思维+set维护

    题意:初始有序列a为n个2,Q次操作. 操作1:将[l,r]的点变为1. 操作2:将[l,r]的点变为2. 在每次操作过后输出序列a有多少个2. n<=1e9 ,Q<=3e5. 将[l,r ...

  6. codeforces 915 E 896 C 珂朵莉树

    珂朵莉树(Chtholly Tree),一种基于std::set的暴力数据结构,是由某毒瘤在2017年的一场CF比赛中提出的数据结构,原名老司机树(Old Driver Tree,ODT).由于第一个 ...

  7. 记第一场cf比赛(Codeforces915)

    比赛感想 本来21:05开始的比赛,结果记成21:30了...晚了25分钟才开始[捂脸] 这次是Educational Round,所以还比较简单. 前两道题一眼看去模拟+贪心,怕错仔细看了好几遍题, ...

  8. 珂朵莉树/ODT 学习笔记

    珂朵莉树/ODT 学习笔记 起源自 CF896C.珂朵莉yyds! 核心思想 把值相同的区间合并成一个结点保存在 set 里面. 用处 骗分.只要是有区间赋值操作的数据结构题都可以用来骗分.在数据随机 ...

  9. 算法自学__珂朵莉树

    参考资料: https://zhuanlan.zhihu.com/p/106353082 https://blog.csdn.net/CC_dsm/article/details/98166835 珂 ...

最新文章

  1. android广播intent原理,Android中BroadcastReceiver详解
  2. 550 Ip frequency limited
  3. 160个Crackme008
  4. ABAP where used list
  5. java反射减少servlet_利用java 反射机制来实现一个servlet处理多种请求
  6. java jtable刷新_java-单击按钮更新JTable
  7. ListView与Button共存问题
  8. 湖南计算机对口专科学校,湖南计算机专业对口升学有哪些学校?
  9. php mongoclient使用,PHP使用mongoclient简单操作mongodb数据库示例
  10. 关于软件测试学习的心得
  11. adb命令连接模拟器,could not read ok from ADB Server
  12. 启动提示archlinux中virtualbox无法运行问题解决
  13. 【丐中丐】废旧光驱改装激光雕刻机
  14. 【老生谈算法】matlab实现无标度网络算法源码——无标度网络
  15. keil数字钟c语言,在 keil 中完成数字钟的演示
  16. vue生命周期 阿星小栈
  17. 直播倒计时android,直播代码,Android实现验证码倒计时
  18. OpenCV 文字绘制cv::putText详解
  19. 《Python编程 从入门到实践》
  20. python井字棋如何判断输赢_Python|找出井字棋的获胜者

热门文章

  1. ansys命令流_ANSYS命令流建模3之划分单元+施加弹簧
  2. 下标索引必须为正整数类型或逻辑类型_Python3 基本数据类型
  3. 怎么用PHP实现年月日date,PHP date函数用法,php年月日写法
  4. mongo 唯一约束索引_快速掌握mongoDB(三)——mongoDB的索引详解
  5. C语言开发笔记(八)static
  6. C语言开发笔记(七)const和指针
  7. c语言软件幻化,python字符串处理
  8. 字节字符区别Java_【JAVA基础】字符数组与字节数组的区别
  9. 套接字编程---2(TCP套接字编程的流程,TCP套接字编程中的接口函数,TCP套接字的实现,TCP套接字出现的问题,TCP套接字多进程版本,TCP套接字多线程版本)
  10. 套接字编程--1(UDP协议编程,端口号,传输层协议,网络字节序)