Physical Education Lessons Codeforces - 915E
http://codeforces.com/problemset/problem/915/E
大概有几种思路:
1.动态开点线段树+标记下传
#1.1标记永久化:想了一会没想出来
1.2可以先扫一遍询问把所有需要的点建出来,然后pushdown就不管没建出来的点了,空间跟标记永久化一样
2.离散化+线段树
3.用splay维护区间(估计没人愿意去写)
4.用一个set<pair<int,int>>记所有非工作日(或工作日)区间,修改就暴力找到相关的区间去改
由于每一次操作最多多出O(1)个区间,因此尽管有时会一次删掉多个区间,但复杂度是对的
#include<cstdio>
#include<algorithm>
#include<set>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;
set<P> s;
set<P>::iterator it;
int ans,n,q;
int main()
{
int i,idx,l,r;P t;
scanf("%d%d",&n,&q);ans=n;s.insert(P(n,));
while(q--)
{
scanf("%d%d%d",&l,&r,&idx);
it=s.lower_bound(P(l,));
if(it!=s.end()&&it->se<=l)
{
t=*it;s.erase(it);
if(l!=t.se) s.insert(P(l-,t.se));
s.insert(P(t.fi,l));
}
it=s.lower_bound(P(r,));
if(it!=s.end()&&it->se<=r)
{
t=*it;s.erase(it);
if(t.fi!=r) s.insert(P(t.fi,r+));
s.insert(P(r,t.se));
}
for(it=s.lower_bound(P(l,));it!=s.end()&&it->fi<=r;it=s.lower_bound(P(l,)))
ans-=it->fi-it->se+,s.erase(it);
if(idx==) s.insert(P(r,l)),ans+=r-l+;
printf("%d\n",ans);
}
return ;
}
Physical Education Lessons Codeforces - 915E的更多相关文章
- 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
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
- Codeforces 915E. Physical Education Lessons(动态开点线段树)
E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...
- Codeforces 915 E Physical Education Lessons
题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...
- 【CodeForces】915 E. Physical Education Lessons 线段树
[题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...
- 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 ,而是这个值与下一个点的差值. 因为这个数代表 ...
随机推荐
- 多平台密码绕过及提权工具Kon-Boot的使用与防范
在单用户的机器上密码可能没那么重要,但是一旦有多个用户可以使用这台机器,密码就显得十分必要了(比如有儿童账户的电脑).所以说为你的电脑增设一条防线的最常用,最简单的方法就是用密码将你的电脑保护起来,但 ...
- Java多线程导致的的一个事物性问题
业务场景 我们如今有一个类似于文件上传的功能.各个子网站接受业务,业务上传文件,各个子网站的文件须要提交到总网站保存.文件是按批次提交到总网站的,也就是说,一个批次以下约有几百个文件. 考虑到白天提交 ...
- [Angular] Architectures for Huge Angular Based Enterprise
Using Angular CLI v6, we are able to create library or small application inside a Angular CLI genera ...
- hibernate查询之Criteria实现分页方法(GROOVY语法)
public int searchTest(String name, Integer pageIndex, List<Test> resultList){ def criteria = T ...
- 同步定制 Unity团队 程序的C#文件模板
孙广东 2015.7.30 就是把程序制定好的模板(不论什么人能够更改并同步git)放到,unity项目的Editor 目录下, 当程序新建一个C#脚本后就是这个模板了. "81-C# ...
- win8 metro 自己写摄像头录像项目
这是要求不适用CameraCaptureUI等使用系统自带的 camera UI界面.要求我们自己写调用摄像头摄像的方法,如今我把我的程序贴下: UI界面的程序: <Page x:Class= ...
- Redis和Memcache性能测试对比
Redis和Memcache在写入性能上面差别不大,读取性能上面尤其是批量读取性能上面Memcache全面胜出,当然Redis也有自己的优点:比如数据持久化.支持更多的数据结构(Set List ZS ...
- 为Html.EditorForModel自定义模版
对于MVC视图渲染来说,大家应该不会陌生,但对于模型的渲染,不知道是否听说过,主要是说Model通过它属性的相关特性(DataType,UIHint)来将它们自动渲染到View上,这是一个比较不错的技 ...
- Django初识二
1,在django中用于提交的form表单中的三要素: 1.1>form标签要有action和method,上传文件需要额外指定的enctype 1.2>获取用户输入的标签要有name属性 ...
- 什么是 jQuery EasyUI
jQuery EasyUI 是一个基于 jQuery 的框架,集成了各种用户界面插件. jQuery EasyUI 框架提供了创建网页所需的一切,帮助您轻松建立站点. easyui 是一个基于 jQu ...