【题解】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) 题意:用线段树做 ...
随机推荐
- js模拟栈---汉诺塔
var Stack = (function(){ var items = new WeakMap(); //先入后出,后入先出 class Stack{ constructor(){ items.se ...
- Amazon RDS多区域高可用测试
最近在AWS上面需要部署一组多区域RDS集群,AWS的多区域简单理解就是RDS一主一从分别在当地的两个机房(两个区域).所以就有了下面各方面的测试. 我们需要测试什么? Primary挂掉时,Seco ...
- 初尝Web API《转》
HTTP 并不是只能用在网页中.它其实还是一个强大的平台,可以用来生成一些API,暴露服务和数据.HTTP很简单灵活,还非常普及.几乎所有你能想到的平台都有HTTP库,所以HTTP服务可以囊括很大范围 ...
- jenkins 添加 证书凭证Credentials
jenkins 添加 证书凭证Credentials 大家都知道jenkins在拉取git项目代码的时候,如果没有配置 “证书凭证Credentials” 或者配置的不对, 就会出现红色报错,最终导致 ...
- JAVA编程思想学习笔记5-chap13-15-斗之气5段
1.String对象不可变,一旦发生字符变换或者变长度,一定是新建了一个String private final char value[]; 2.字符串+与+=:唯二操作符重载 "aaa&q ...
- setUp和tearDown及setUpClass和tearDownClass的用法及区别
① setup():每个测试函数运行前运行 ② teardown():每个测试函数运行完后执行 ③ setUpClass():必须使用@classmethod 装饰器,所有test运行前运行一次 ④ ...
- 理解tcp顺序释放操作和tcp的半关闭
Shutdown的调用 在关闭socket的时候,可以有两种方式closesocket和shutdown,这两个函数的区别在什么地方呢? #include <sys/socket. ...
- mint-ui Picker的使用
<template> <div v-bind:style="{minHeight:clientHeight + 'px'}" id="recive-mi ...
- scala mysql jdbc oper
package egsql import java.util.Properties import com.sun.org.apache.xalan.internal.xsltc.compiler.ut ...
- Unity shader学习之菲涅耳反射
菲涅尔反射(Fresnel reflection),指光线照射物体表面时,一部分发生反射,一部分进入物体内部发生折射或散射,被反射的光和折射光之间存在一定的比率. 2个公式: 1. Schlick 菲 ...