原题传送门:CF915E Physical Education Lessons

前置芝士:珂朵莉树

窝博客里对珂朵莉树的介绍

没什么好说的自己看看吧

这道题很简单啊

每个操作就是区间赋值,顺带把总和修改一下,这样会快多了,所以我又成了洛咕最优解第二(好像比23forever dalao快,玄学???)

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define IT set<node>::iterator
using namespace std;
inline int read()
{
register int x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct node
{
int l,r;
mutable bool v;
node(int L, int R=-1, bool V=0):l(L), r(R), v(V) {}
bool operator<(const node& o) const
{
return l < o.l;
}
};
set<node> s;
int sum=0;
IT split(int pos)
{
IT it = s.lower_bound(node(pos));
if (it != s.end() && it->l == pos)
return it;
--it;
int L = it->l, R = it->r;
bool V = it->v;
s.erase(it);
s.insert(node(L, pos-1, V));
return s.insert(node(pos, R, V)).first;
}
void assign_val(int l,int r,bool val)
{
IT itr = split(r+1), itl = split(l), it = itl;
for( ;itl != itr; ++itl)
sum-=itl->v*(itl->r-itl->l+1);
s.erase(it,itr);
s.insert(node(l,r,val));
sum+=val*(r-l+1);
}
int main()
{
int n=read(),m=read();
s.insert(node(1,n,1));
sum=n;
while(m--)
{
int l=read(),r=read(),op=read();
if(op==1)
assign_val(l,r,0);
else
assign_val(l,r,1);
printf("%d\n",sum);
}
return 0;
}

【题解】Luogu CF915E Physical Education Lessons的更多相关文章

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

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

  2. CF915E Physical Education Lessons

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

  3. CF915E Physical Education Lessons 珂朵莉树

    问题描述 CF915E LG-CF915E 题解 \(n \le 10^9\) 看上去非常唬人. 但是这种区间操作的题,珂朵莉树随便跑啊. \(\mathrm{Code}\) #include< ...

  4. CF915E Physical Education Lessons(珂朵莉树)

    中文题面 据说正解是动态开点线段树而且标记也不难下传的样子 然而这种区间推平的题目还是喜欢写珂朵莉树啊……码量小…… 虽然真要构造的话随便卡…… //minamoto #include<cstd ...

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

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

  6. Codeforces 915E Physical Education Lessons

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

  7. Codeforces 915 E Physical Education Lessons

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

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

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

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

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

随机推荐

  1. CentOS6.5配置MYSQL一主多从详解

    一.环境 操作系统 :CentOS 6.5 数据库版本:MySQL 主机A:192.168.1.1 (Master) 从机B:192.168.1.2 (Slave) 从机B:192.168.1.3 ( ...

  2. Groovy动态解析

    A:前面需要说些什么吗? B:不需要吗? A:需要吗? 解析方式一:通过指定的paths来初始化GroovyScriptEngine //通过指定的paths来初始化GroovyScriptEngin ...

  3. 数据分析与挖掘 - R语言:贝叶斯分类算法(案例一)

    一个简单的例子!环境:CentOS6.5Hadoop集群.Hive.R.RHive,具体安装及调试方法见博客内文档. 名词解释: 先验概率:由以往的数据分析得到的概率, 叫做先验概率. 后验概率:而在 ...

  4. 20165321 实验三 敏捷开发与XP实践

    任务1: 要求: 参考 http://www.cnblogs.com/rocedu/p/6371315.html#SECCODESTANDARD 安装alibaba 插件,解决代码中的规范问题. 在I ...

  5. shader之法线变换

    对于法线变换,进行非统一缩放时,如果使用跟变换顶点相同的变换矩阵来变换法线,则会得到错误的结果,即变换后的法线方向与平面不再垂直. 如何求得变换法线的矩阵呢: 转载请注明出处:http://www.c ...

  6. python base64加密文本内容(2)

    上面一篇简单进行了base64加密 但安全系数非常低,只需要用网上的在线base64解码就能破解 这里我们可以自己修改一下base64加密后的字符串,在解码的时候只需要先提前将修改的内容还原就可以了 ...

  7. Operation(Swift)

    介绍: NSOperation需要配合NSOperationQueue来实现多线程.因为默认情况下,NSOperation单独使用时系统同步执行操作,并没有开辟新线程的能力,只有配合NSOperati ...

  8. [openjudge-搜索]深度优先搜索之马走日

    题目描述 描述 马在中国象棋以日字形规则移动.请编写一段程序,给定n*m大小的棋盘,以及马的初始位置(x,y),要求不能重复经过棋盘上的同一个点,计算马可以有多少途径遍历棋盘上的所有点. 输入 第一行 ...

  9. css 箭头

    .toTop{ width: 2.5rem; height: 2.5rem; background-color: rgba(228,228,228,.6); position: fixed; bott ...

  10. 1.python虚拟环境的安装-用以同时使用py2,py3

    第一步:安装环境支持[linux下在前加sudo] http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycurl pip install virtualenv 第 ...