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神 ...
随机推荐
- GRE与VXLAN
一 GRE 1.1 概念 GRE全称是Generic Routing Encapsulation,是一种协议封装的格式,具体格式内容见:https://tools.ietf.org/html/rfc2 ...
- Bootstrap开发框架界面的调整处理
我在之前介绍了很多关于Boostrap的框架方面的文章,主要是介绍各种插件的使用居多,不过有时候觉得基于Metronic的Boostrap框架的界面效果不够紧凑,希望对它进行一定的调整,那么我们应该如 ...
- Winform数据库连接app.config文件配置
1.添加配置文件 新建一个winform应用程序,类似webfrom下有个web.config,winform下也有个App.config;不过 App.config不是自动生成的需要手动添加,鼠标右 ...
- MySQL数据类型的选择
+++++++++++++++++++++++++++++++++++++++++++标题:MySQL数据类型的选择时间:2019年2月22日内容:MySQL数据类型的选择范式参考重点:主要讲述MyS ...
- IntentService+BroadcastReceiver 实现定时任务
效果图: AlramIntentService package com.example.admin.water; import android.app.AlarmManager;import andr ...
- SpringCloud学习笔记:服务注册与发现Eureka(2)
1. Eureka简介 Eureka是一个用于服务注册和发现的组件,分为Eureka Server和Eureka Client,Eureka Server为Eureka服务注册中心,Eureka Cl ...
- 学习Spring Boot:(十五)使用Lombok来优雅的编码
前言 Lombok 是一种 Java™ 实用工具,可用来帮助开发人员消除 Java 的冗长,尤其是对于简单的 Java 对象(POJO).它通过注解实现这一目的. 正文 添加依赖 在 pom.xml ...
- purge旧的ubuntu 的linux内核
https://www.sysgeek.cn/remove-old-kernels-ubuntu-16-04/
- Codeforces 1082B Vova and Trophies(前缀+后缀)
题目链接:Vova and Trophies 题意:给定长度为n的字符串s,字符串中只有G和S,只允许最多一次操作:任意位置的两个字符互换.求连续G的最长长度. 题解:维护pre和pr,nxt和nx. ...
- 解决mysql表不能查询修改删除等操作并出现卡死
问题现象1:进程wait卡住 测试环境mysql出现了一个怪表:select查询表卡死,alter修改表卡死,甚至我不想要这个表了,delete.truncate.drop表都卡死卡主了...... ...