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神 ...
随机推荐
- go笔记-限速器(limiter)
参考: https://blog.csdn.net/wdy_yx/article/details/73849713https://www.jianshu.com/p/1ecb513f7632 http ...
- Kafka 详解(一)------简介
在前面几篇博客我们介绍过一种消息中间件——RabbitMQ,本篇博客我们介绍另外一个消息中间件——Kafka,Kafka是由LinkedIn开发的,使用Scala编写,是一种分布式,基于发布/订阅的消 ...
- iOS开发基础-UITableView基本属性
设置 UITableView 中 cell 的背景颜色. 示例1:通过 backgroundView 设置. UIView *view1 = [[UIView alloc] init]; view1. ...
- SpringBoot中各配置文件的优先级及加载顺序
我们在写程序的时候会碰到各种环境(开发.测试.生产),因而,在我们切换环境的时候,我们需要手工切换配置文件的内容.这大大的加大了运维人员的负担,同时会带来一定的安全隐患. 为此,为了能更合理地重写各属 ...
- python中打印中文
python中打印中文 在python 2.x版本中,默认是ASCII编码方式,在有业务需要输入中文时,就会出现乱码的情况.解决这种问题的一个方式就是设置py文件的编码方式.实现方式如下: 在py文件 ...
- mybatis 使用auto mapping原理实现表间关联
Auto mapping的示例 数据库中有一个person表,结构如下: mysql> desc person; +-------+-------------+------+-----+---- ...
- ubuntu 18.04安装pytorch、cuda、cudnn等
版权声明:本文为博主原创文章,欢迎转载,并请注明出处.联系方式:460356155@qq.com ubuntu 16.04用了1年多了,18.04版已经发布也半年了,与时俱进,重装Linux系统,这里 ...
- Linux下用户和raid练习题
1. 公司一开发人员申请对服务器10天的oldboy普通用户权限,如何操作? useradd oldboy passwd oldboy usermod -e `date -d "10day& ...
- 跨域下使用获取iframe的父页面URL
通常情况下,我们获取iframe父页面的url很简单:parent.location或top.location即可,但前提是它们遵循同源策略. 当iframe与父页面不属于同一个域名时,像上面的获取会 ...
- 企业nginx应用实例(功能拆分记录)
一.默认访问协议强制跳转(http--->https) server { listen ; server_name dannylinux.top www.dannylinux.top; # re ...