codeforces 915E - Physical Education Lessons 动态开点线段树
题意:
最大$10^9$的区间,
$3*10^5$次区间修改,每次操作后求整个区间的和
题解:
裸的动态开点线段树,计算清楚数据范围是关键...
经过尝试
$2*10^7$会$MLE$
$10^7$会$RE$
用$vector$但是一开始没有$resize$到最大也会$MLE$
如果节点内部信息保存了节点的区间,无论怎么样都会$MLE$
最终$1.5*10^7$的$vector$/数组可以过
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+5e6+7;
class dsegtree{public:
#define nd node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
struct dsegnode {
int son[2],tag,sum;
dsegnode(){}
dsegnode(int s,int t){sum=t-s+1,tag=son[0]=son[1]=0;}
void update(int x,int len){sum=len*(x-1),tag=x;}
};
vector<dsegnode> node;
int root,cnt,n,s,t;
dsegtree(int nn,int size=maxn){
n=nn;
node.resize(maxn);
node[1]=dsegnode(1,n);
cnt=root=1;
}
void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
void pushdown(int now,int s,int t){
if(nd.tag){
ndl.update(nd.tag,(t+s)/2-s+1);
ndr.update(nd.tag,t-((t+s)/2+1)+1);
nd.tag=0;
}
}
void update(int ss,int tt,int x){s=ss,t=tt,update(1,n,x,root);}
void update(int l,int r,int x,int now){
if(s>r||t<l)return ;
if(s<=l&&t>=r) {
nd.update(x,r-l+1);
return ;
}
if(!nd.son[0]){
node[++cnt]=dsegnode(l,(l+r)>>1);
nd.son[0]=cnt;
}
if(!nd.son[1]){
node[++cnt]=dsegnode(((l+r)>>1)+1,r);
nd.son[1]=cnt;
}
pushdown(now,l,r);
update(l,(l+r)>>1,x,nd.son[0]);
update(((l+r)>>1)+1,r,x,nd.son[1]);
pushup(now);
}
}; int main() {
IO;
ll n,m;
cin>>n>>m;
dsegtree tree(n);
int a,b,c;
while(m--){
cin>>a>>b>>c;
tree.update(a,b,c);
cout<<tree.node[tree.root].sum<<endl;
}
return 0;
}
91
题解5
codeforces 915E - Physical Education Lessons 动态开点线段树的更多相关文章
- codeforces 893F - Physical Education Lessons 动态开点线段树合并
		
https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的 ...
 - CF915E Physical Education Lessons 动态开点线段树
		
题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...
 - Codeforces 915E Physical Education Lessons
		
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
 - Codeforces 915E. Physical Education Lessons(动态开点线段树)
		
E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...
 - Physical Education Lessons CodeForces - 915E  (动态开点线段树)
		
Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...
 - CodeForces - 915E  动态开点线段树
		
题目 晚上有n个亮着的灯泡,标号从1到n. 现在存在2种操作,如下: 操作1,关掉标号 [l,r] 区间的灯 操作2,打开标号 [l,r] 区间的灯 下面有q次询问,每次询问执行其中一种操作,询问格式 ...
 - CF915E Physical Education Lessons(珂朵莉树)
		
中文题面 据说正解是动态开点线段树而且标记也不难下传的样子 然而这种区间推平的题目还是喜欢写珂朵莉树啊……码量小…… 虽然真要构造的话随便卡…… //minamoto #include<cstd ...
 - Codeforces 803G Periodic RMQ Problem ST表+动态开节点线段树
		
思路: (我也不知道这是不是正解) ST表预处理出来原数列的两点之间的min 再搞一个动态开节点线段树 节点记录ans 和标记 lazy=-1 当前节点的ans可用 lazy=0 没被覆盖过 els ...
 - [2016湖南长沙培训Day4][前鬼后鬼的守护 chen] (动态开点线段树+中位数 or 动规 or 贪心+堆优化)
		
题目大意 给定一个长度为n的正整数序列,令修改一个数的代价为修改前后两个数的绝对值之差,求用最小代价将序列转换为不减序列. 其中,n满足小于500000,序列中的正整数小于10^9 题解(引自mzx神 ...
 
随机推荐
- iOS开发基础-UITableView控件简单介绍
			
UITableView 继承自 UIScrollView ,用于实现表格数据展示,支持垂直滚动. UITableView 需要一个数据源来显示数据,并向数据源查询一共有多少行数据以及每一行显示什么 ...
 - Bootstrap开发框架视频整理
			
最近到客户处进行实地培训,整理了很多培训的材料,现将它们录制相关主题的视频,作为我的Bootstrap开发框架的知识补充,希望给感兴趣的朋友进行了解.培训内容主要包括基础框架部分.MVC框架部分.Bo ...
 - H5调用手机拍照并展示在前端页面
			
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
 - 控制结构(3): 状态机(state machine)
			
// 上一篇:卫语句(guard clause) // 下一篇:局部化(localization) 基于语言提供的基本控制结构,更好地组织和表达程序,需要良好的控制结构. 前情回顾 上次分析了guar ...
 - mysql varchar  integer
			
MySQL 中将 varchar 字段转换成数字进行排序 - MySQL - 大象笔记 https://www.sunzhongwei.com/order-by-varchar-field-which ...
 - 酷炫的loading
			
今天分享一下,怎么通过用css写出一个酷炫的loading. meta: <meta name="viewport" content="width=device-w ...
 - java  反射的基本操作
			
一.反射的概述JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称为j ...
 - springdataJAP的更新与保存的方法是同一个
			
对于save方法的解释:如果执行此方法是对象中存在id属性,即为更新操作会先根据id查询,再更新 如果执行此方法中对象中不存在id属性,即为保存操作
 - eclipse报错 : One or more constraints have not been satisfied.
			
当eclipse进行报错时,但是不影响运行时,这种错误一般是编译时的问题 进行修改3个地方,即可完成 一 : 进行修改这三个地方的配置文件,都改成你统一的jdk版本,和你用的Dynamic Web ...
 - docker完整配置nginx+php+mysql
			
首先了解一个方法: 使用docker exec进入Docker容器 docker在1.3.X版本之后还提供了一个新的命令exec用于进入容器,这种方式相对更简单一些,下面我们来看一下该命令的使用: s ...