Codeforces 915 E Physical Education Lessons
题目描述
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.
输入输出样例
4
6
1 2 1
3 4 1
2 3 2
1 3 2
2 4 1
1 4 2
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的更多相关文章
- 【CodeForces】915 E. Physical Education Lessons 线段树
[题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...
- 【Codeforces 915E】 Physical Education Lessons
[题目链接] 点击打开链接 [算法] 线段树,注意数据量大,要动态开点 [代码] #include<bits/stdc++.h> using namespace std; ; ,root ...
- Codeforces 915E Physical Education Lessons
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
- Physical Education Lessons CodeForces - 915E (动态开点线段树)
Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...
- Codeforces 915E. Physical Education Lessons(动态开点线段树)
E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...
- CF915E Physical Education Lessons 动态开点线段树
题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...
- 【题解】Luogu CF915E Physical Education Lessons
原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...
- CF915E Physical Education Lessons
题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...
- 线段树 离散化 E. Infinite Inversions E. Physical Education Lessons
题目一:E. Infinite Inversions 这个题目没什么思维量,还比较简单,就是离散化要加上每一个值的后面一个值,然后每一个值放进去的不是1 ,而是这个值与下一个点的差值. 因为这个数代表 ...
随机推荐
- <video>标签的特性
以前的网页视频 过去还没有HTML5的时候,我们处理网页视频的时候,都是通过Flash插件来实现的,然而,并非所有浏览器都有同样的插件. 现在有了HTML5带来的video元素,开发者能够很方便地将视 ...
- Java拷贝构造函数初尝试
浅复制(浅克隆) :被复制对象的所有变量都含有与原来的对象相同的值,而所有的对其他对象的引用仍然指向原来的对象.换言之,浅复制仅仅复制所考虑的对象,而不复制它所引用的对象. 深复制(深克隆) :被复制 ...
- es6快速排序
let qsort = fn =>([x,...xn]) => x == null ? [] : [ ...qsort(fn)(xn.filter(a=>fn(a,x))), x, ...
- 复选框 checkbox 选中事件
项目中用的jquery-1.11 今天需要检测一个checkbox的选中状态,想当然的用 .attr("checked") ,结果发现,无论是否选中,这个值都是 undefined ...
- HDU1272---(并查集)简单应用
http://acm.hdu.edu.cn/showproblem.php?pid=1272 小希的迷宫 Time Limit: 2000/1000 MS (Java/Others) Memor ...
- rest service技术选型
MySql workbench下载 http://dev.mysql.com/downloads/workbench/ 最好的8个 Java RESTful 框架 http://colobu.com/ ...
- 【BZOJ】1691: [Usaco2007 Dec]挑剔的美食家
[算法]扫描线+平衡树(set) [题解]很明显的二维偏序数点,排序后扫描线,现加点后查询答案. 则问题转化为一维偏序,显然贪心找第一个比当前大的最优,所以用平衡树维护. 记得开multiset!!! ...
- kuangbin 带你飞 概率期望
正推不行就逆推! 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小人数. 这就是邮票收集问题的变形:每个邮票至少出现一次的概率 小于等于 0.5 邮票收集问题 ...
- JQ子页面对父页面的元素进行操作
需要加上parent.document,才能找到父页面的元素 如: $("#tabs", parent.document).click();
- 【 Ngnix 】配置路径转发至后端Apache多台虚拟主机
一.安装apache并开启端口 [root@server ~]# netstat -ntplu | grep httpd tcp /httpd tcp /httpd 二.nginx配置 locatio ...