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 ,而是这个值与下一个点的差值. 因为这个数代表 ...
随机推荐
- bulk_insert_buffer_size and InnoDB
Q: I read the following on this page http://dev.mysql.com/doc/mysql/en/server-system-variables.html ...
- Why is the ibdata1 file continuously growing in MySQL?
We receive this question about the ibdata1 file in MySQL very often in Percona Support. The panic st ...
- [poj 2274]后缀数组+最长公共子串
题目链接:http://poj.org/problem?id=2774 后缀数组真的太强大了,原本dp是O(nm)的复杂度,在这里只需要O(n+m). 做法:将两个串中间夹一个未出现过的字符接起来,然 ...
- POJ1637:Sightseeing tour(混合图的欧拉回路)
Sightseeing tour Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10581 Accepted: 4466 ...
- angular js的Inline Array Annotation的理解
inline Array annotation的形式是: someModule.controller('MyController', ['$scope', 'greeter', function($s ...
- Django请求原理
总结一下: 1. 进来的请求转入/hello/. 2. Django通过在ROOT_URLCONF配置来决定根URLconf. 3. Django在URLconf中的所有URL模式中,查找第一个匹配/ ...
- 新手如何更换自己喜欢的背景以及此背景的css码
以下内容为转载(对于css码可以自己写当然也可以去网上搜现成的): 更换背景教学:https://jingyan.baidu.com/album/fc07f9897c730412ffe519c0.ht ...
- Android 网络编程--上传文件及相应的参数到服务器
之前一直在做SiteCheck的项目,所用到的知识大部分都涉及到网络编程方面,所以现在有时间先把它的使用方法及一些注意事项记录下来.在这里我用两种例子让大家了解它的使用方法: (1)上传图片及相应参数 ...
- 复选框 checkbox 选中事件
项目中用的jquery-1.11 今天需要检测一个checkbox的选中状态,想当然的用 .attr("checked") ,结果发现,无论是否选中,这个值都是 undefined ...
- nodejs与sqlite
//打开数据库var db = new sqlite3.Database('xx.db'); // 关闭数据库db.close(); db.run('xx'); // 数据库对象的run函数可以执行 ...