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 ,而是这个值与下一个点的差值. 因为这个数代表 ...
随机推荐
- HTML大文件上传(博客迁移)
Html大文件上传:跳转 通过github和hexo进行搭建博客,主要是在没有网络的时候,可以本地访问,并支持markdown语法. 新博客地址:跳转
- Atitit.软件仪表盘(7)--温度监測子系统--电脑重要部件温度与监控and警报
Atitit.软件仪表盘(7)--温度监測子系统--电脑重要部件温度与监控and警报 Cpu温度.风扇转速 主板温度 显卡温度 硬盘温度 电池温度 鲁大师 硬盘温度 Cpu温度 core temp ...
- POI 的使用
POI 使用 一. POI简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能..NET的开发人员则 ...
- python3 base64模块代码分析
#! /usr/bin/env python3 """Base16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data ...
- 【bzoj2152】【聪聪可可】【点分治】
[问题描写叙述] 聪聪和可但是兄弟俩.他们俩常常为了一些琐事打起来,比如家中仅仅剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(但是他们家仅仅有一台电脑)--遇到这样的问题,普通情况下石头剪刀布就好 ...
- Unity构造函数注入代码示例
Unity构造函数注入代码示例 如果使用 Unity 实例化一个类,该类的构造函数依赖一个或多个其他类,则 Unity 会为构造函数自动创建参数中指定的被依赖的类的实例.例如,下面的代码展示了一个名为 ...
- 转载 Url编码
http://www.cnblogs.com/artwl/archive/2012/03/07/2382848.html 混乱的URI编码 JavaScript中编码有三种方法:escape.enco ...
- HDU 2457/POJ 3691 DNA repair AC自动机+DP
DNA repair Problem Description Biologists finally invent techniques of repairing DNA that contains ...
- 【Java报错】Message: 3 字节的 UTF-8 序列的字节 2 无效
报错logs 2015-03-10 10:15:32,360 ERROR [qtp32195030-27] [InvokeAfterValve.java:55] - javax.xml.stream. ...
- Android Studio配置完毕Genymotion 看不到Genymotion图标
没有打开toolBar想要看到genymotion插件图标,AndroidStudio单击视图(view)>工具栏显示工具栏(toolbar)