【题解】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) 题意:用线段树做 ...
随机推荐
- vue使用md5加密
import crypto from 'crypto' export default { name: 'HelloWorld', data () { return { msg: 'Welcome to ...
- Amber TUTORIAL B5: Simulating the Green Fluorescent Protein
Section 1: Preparing the PDB file 1EMA是本次教程所用的pdb,可以在PDB数据库下载. pdb4amber -i 1EMA.pdb -o gfp.pdb --dr ...
- 数据加密之MD5加密
MD5是一个安全的散列算法,有两个特点:1.输入两个不同的明文(一段原始的数字信息)不会得到相同的输出值2.根据输出值,不能得到原始的明文,即过程不可逆所以要解密MD5没有现成的算法,只能用穷举法,把 ...
- Thinkphp 3.2 验证码图片显示错误解决方法
在调用验证码之前加上 ob_clean(); 不显示验证码的代码: public function verify(){ $verify = new \Think\Verify(); $verify-& ...
- CSU 1857 Crash and Go(relians)(模拟)
Crash and Go(relians) [题目链接]Crash and Go(relians) [题目类型]模拟 &题解: 这就是要严格的按照题意说的模拟就好了,也就是:每次添加进来一个圆 ...
- LeetCode108.将有序数组转换为二叉搜索树
将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. 示例: 给定有序数组: [-10,-3,0, ...
- 如何使用Apache log4net库与ASP.NET MVC 5日志记录
在运行软件程序的时候,跟踪和监控日志是一种记录过程的好方法. 简介: 在运行软件程序的时候,跟踪和监控日志是一种记录过程的好方法.尤其在应用程序出错的时候,日志是我们最需要的文件.不管是在web,wi ...
- jdbc连接oracle时使用的字符串格式
两种方式: SID的方式: jdbc:oracle:thin:@[HOST][:PORT]:SID SERVICE_NAME的方式: jdbc:oracle:thin:@//[HOST][:PORT] ...
- 学习笔记<3>View接触
一.View基本概念 1.界面上显示所有的控件都是用对象表示的,即有类,这些类都是View的子类. 2.View的种类 二.在Activity当中获取代表View的对象 1.根据ID可以用方法获取到对 ...
- jQuery属性--html([val|fn])、text([val|fn])和val([val|fn|arr])
html([val|fn]) 概述 取得第一个匹配元素的html内容,这个函数不能用于XML文档.但可以用于XHTML文档. 在一个 HTML 文档中, 我们可以使用 .html() 方法来获取任意一 ...