【题解】Luogu CF915E Physical Education Lessons
原题传送门: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的更多相关文章
- CF915E Physical Education Lessons 动态开点线段树
题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...
- CF915E Physical Education Lessons
题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...
- CF915E Physical Education Lessons 珂朵莉树
问题描述 CF915E LG-CF915E 题解 \(n \le 10^9\) 看上去非常唬人. 但是这种区间操作的题,珂朵莉树随便跑啊. \(\mathrm{Code}\) #include< ...
- CF915E Physical Education Lessons(珂朵莉树)
中文题面 据说正解是动态开点线段树而且标记也不难下传的样子 然而这种区间推平的题目还是喜欢写珂朵莉树啊……码量小…… 虽然真要构造的话随便卡…… //minamoto #include<cstd ...
- 【CodeForces】915 E. Physical Education Lessons 线段树
[题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...
- Codeforces 915E Physical Education Lessons
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
- Codeforces 915 E Physical Education Lessons
题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...
- 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) 题意:用线段树做 ...
随机推荐
- Java - Selenium 环境配置
1. 安装Java JDK - 文件自己下 2. 配置环境变量-重要! 我的电脑-属性-高级-环境变量 添加 CLASSPATH 值 .;%JAVA_HOME%\lib;%JAVA_HOME%\li ...
- 第三章Div水平居中
1.div居中 text-align:center可以让元素里面的文字内容居中,但并不能让div居中.要让div水平居中必须设置div宽度,外边距设置为margin:0 auto <%@ Pag ...
- CI持续集成系统环境--Gitlab+Gerrit+Jenkins完整对接
原文地址https://www.cnblogs.com/kevingrace/p/5651447.html 近年来,由于开源项目.社区的活跃热度大增,进而引来持续集成(CI)系统的诞生,也越发的听到更 ...
- python我的tkinter学习,玩玩
1.开始 #!/usr/bin/env python #coding:utf-8 import Tkinter ############################################ ...
- EF There is already an open DataReader associated with this Command
捕捉到 System.InvalidOperationException _HResult=-2146233079 _message=意外的连接状态.在使用包装提供程序时,请确保在已包装的 DbCon ...
- leetCodelinked-list-cycle-ii找到链表的环
题目 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. N ...
- 面向对象的多态性(C++)
以C++为例三大特效:封装.继承.多态,面向对象的编程语言都具有这些特性. 那么本节来谈谈多态性,尽量说的简单些容易理解! 多态什么意思?即运行时多态,以相同的方式处理不同类型的对象,产生不同的结果! ...
- HTTP GET的VC三种方式
一.第一种方式(包装类的方式) a.在VC++添加类,选择typelib b.选择文件:C:\Windows\System32\winhttp.dll 选择到右边生成的类,最后点完成,即产生了一个CW ...
- 原生JS实现addClass,removeClass,toggleClass
jQuery操作class的方式非常强大,但是目前还有一些人不知道如何使用或者由于项目统一性的原因无法使用jquery. 在此写了一个利用原生js来实现对dom元素class的操作方法 1.addCl ...
- Sql 嵌套循环
DECLARE @i INT ,@j INT BEGIN PRINT 'satrt i:'+CAST(@i AS varchar) BEGIN PRINT 'j:'+CAST(@j AS varcha ...