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的更多相关文章

  1. Physical Education Lessons CodeForces - 915E (动态开点线段树)

    Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...

  2. Codeforces 915E Physical Education Lessons

    原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...

  3. Codeforces 915E. Physical Education Lessons(动态开点线段树)

    E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...

  4. Codeforces 915 E Physical Education Lessons

    题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...

  5. 【CodeForces】915 E. Physical Education Lessons 线段树

    [题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...

  6. CF915E Physical Education Lessons 动态开点线段树

    题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...

  7. 【题解】Luogu CF915E Physical Education Lessons

    原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...

  8. CF915E Physical Education Lessons

    题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...

  9. 线段树 离散化 E. Infinite Inversions E. Physical Education Lessons

    题目一:E. Infinite Inversions 这个题目没什么思维量,还比较简单,就是离散化要加上每一个值的后面一个值,然后每一个值放进去的不是1 ,而是这个值与下一个点的差值. 因为这个数代表 ...

随机推荐

  1. eclipse中maven插件上传项目jar包到私服

    我们知道,每一个公司都会有自己的工具包或公共包.这样的包就能够上传到公司的maven私服,就不用每一个人都去同步开发包了. 那么,怎么把本地项目打包并公布到私服呢?依照例如以下步骤就能够轻松完毕. 1 ...

  2. IOS开发 ios7适配

    ios7控制器试图默认为全屏显示,导航栏的不同设置会产生不同的效果. 首先判断系统的的版本,区别: if (floor(NSFoundationVersionNumber) <= NSFound ...

  3. delphi 修改文件夹名和文件名

    unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...

  4. 使用MySQL Workbench进行数据库设计——MySQL Workbench用法总结

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/48318877 本文出自[我是干勾鱼的博客] 1 简单介绍 MySQL Workb ...

  5. Spark应用远程调试

    本来想用Eclipse的.然而在网上找了一圈,发现大家都在说IntelliJ怎样怎样好.我也受到了鼓励,遂决定在这台破机器上鼓捣一次IntelliJ吧. Spark程序远程调试,就是将本地IDE连接到 ...

  6. POJ 1061 青蛙的约会(扩展GCD求模线性方程)

    题目地址:POJ 1061 扩展GCD好难懂.. 看了半天.最终把证明什么的都看明确了. .推荐一篇博客吧(戳这里),讲的真心不错.. 直接上代码: #include <iostream> ...

  7. PHP出现Warning: A non-numeric value encountered问题的原因及解决方法

    本文介绍php出现Warning: A non-numeric value encountered问题,用实例分析出现这种错误的原因,并提供避免及解决问题的方法. <?php error_rep ...

  8. mac for smartSVN9 (8,9)破解方法 附smartSvn_keygen工具图文

    mac for  smartSVN9 (8,9)破解方法 附smartSvn_keygen工具 工具文件下载: http://files.cnblogs.com/files/xueshanshan/s ...

  9. [办公自动化]计算机突然断电,微软office文档(有asd文件)如何恢复?

    今天同事使用office软件时,突然故障.结果他忙了半天的word文档内容都找不见了. 经过查找,在其硬盘根目录找到了asd文档. 但是用当前版本的word和高版本的word软件都无法打开. 又查找了 ...

  10. 【bzoj2753】[SCOI2012]滑雪与时间胶囊

    #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> # ...