题目链接

CF915E Physical Education Lessons

题解

动态开点线段树

代码

/*
动态开点线段树
*/
#include<cstdio>
#include<cstring>
#include<algorithm> inline int read() {
int x = 0,f = 1;
char c = getchar() ;
while(c < '0' || c > '9')c = getchar();
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
const int maxn = 500007 * 30;
int rt = 0;
struct Segtree {
int tot ;
int ls[maxn],rs[maxn],tag[maxn],sum[maxn];
void pushdown(int x,int l,int r) {
int mid = l + r >> 1;
if(l != r) {
if(!ls[x]) ls[x] = ++ tot; //记得开点这里
if(!rs[x]) rs[x] = ++ tot;
sum[ls[x]] = (mid - l + 1) * tag[x];
sum[rs[x]] = (r - mid) * tag[x];
tag[ls[x]] = tag[x];
tag[rs[x]] = tag[x];
}
tag[x] = -1;
}
void modify(int &x,int l,int r,int L,int R,int w) {
if(!x) x = ++ tot;
if(l >= L && r <= R) {
sum[x] = (r - l + 1) * w;
tag[x] = w;
return;
}
if(tag[x] >= 0) pushdown(x,l,r);
int mid = l + r >> 1;
if(L <= mid) modify(ls[x],l,mid,L,R,w);
if(R > mid) modify(rs[x],mid + 1,r,L,R,w);
sum[x] = sum[ls[x]] + sum[rs[x]];
}
} t;
int main() {
int n = read();
int m = read();
memset(t.tag,-1,sizeof t.tag);
for(int type,l,r,i = 1;i <= m;++ i) {
l = read(),r = read(),type = read();
if(type == 1) t.modify(rt,1,n,l,r,1);
else t.modify(rt,1,n,l,r,0);
printf("%d\n",n - t.sum[1]);
}
return 0;
}

CF915E Physical Education Lessons 动态开点线段树的更多相关文章

  1. codeforces 893F - Physical Education Lessons 动态开点线段树合并

    https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的 ...

  2. codeforces 915E - Physical Education Lessons 动态开点线段树

    题意: 最大$10^9$的区间, $3*10^5$次区间修改,每次操作后求整个区间的和 题解: 裸的动态开点线段树,计算清楚数据范围是关键... 经过尝试 $2*10^7$会$MLE$ $10^7$会 ...

  3. CF915E Physical Education Lessons(珂朵莉树)

    中文题面 据说正解是动态开点线段树而且标记也不难下传的样子 然而这种区间推平的题目还是喜欢写珂朵莉树啊……码量小…… 虽然真要构造的话随便卡…… //minamoto #include<cstd ...

  4. Physical Education Lessons CodeForces - 915E (动态开点线段树)

    Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...

  5. CF915E Physical Education Lessons

    题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...

  6. 【题解】Luogu CF915E Physical Education Lessons

    原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...

  7. [2016湖南长沙培训Day4][前鬼后鬼的守护 chen] (动态开点线段树+中位数 or 动规 or 贪心+堆优化)

    题目大意 给定一个长度为n的正整数序列,令修改一个数的代价为修改前后两个数的绝对值之差,求用最小代价将序列转换为不减序列. 其中,n满足小于500000,序列中的正整数小于10^9 题解(引自mzx神 ...

  8. [bzoj 3531][SDOI2014]旅行(树链剖分+动态开点线段树)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3531 分析: 对于每个颜色(颜色<=10^5)都建立一颗线段树 什么!那么不是M ...

  9. 【BZOJ-4636】蒟蒻的数列 动态开点线段树 ||(离散化) + 标记永久化

    4636: 蒟蒻的数列 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 247  Solved: 113[Submit][Status][Discuss ...

随机推荐

  1. 『PyTorch』第五弹_深入理解autograd_上:Variable属性方法

    在PyTorch中计算图的特点可总结如下: autograd根据用户对variable的操作构建其计算图.对变量的操作抽象为Function. 对于那些不是任何函数(Function)的输出,由用户创 ...

  2. V4L2文档翻译(一)【转】

    转自:https://blog.csdn.net/airk000/article/details/23218903 相关资料 https://www.kernel.org/doc/Documentat ...

  3. 初识CPU卡、SAM卡/CPU卡简介、SAM卡简介 【转】

    初识CPU卡.SAM卡/CPU卡简介.SAM卡简介 IC卡按照接口方式可分为接触式卡.非接触式卡.复合卡:按器件技术可分为非加密存储卡.加密存储卡和CPU卡. 加密存储卡是对持卡人的认证,只有输入正确 ...

  4. select 不要 用*

    背景 说实在的,这有什么好记录的呢.记录这个有啥用,真是技术人员的吹毛求疵.说起来,就是给人装有用吧.既然记录了,也想个相关的段子吧.曾经有个同事写了个sql,效率极差,来了个女同事,竟然解决了,问题 ...

  5. JS/Jquery版本的俄罗斯方块(附源码分析)

    转载于http://blog.csdn.net/unionline/article/details/63250597 且后续更新于此 1.前言 写这个jQuery版本的小游戏的缘由在于我想通过从零到有 ...

  6. PYTHON-基本数据类型-数字类型,字符串类型,列表类型-练习

    # 字符串练习# 写代码,有如下变量,请按照要求实现每个功能 (共6分,每小题各0.5分)# name = " aleX"# # 1) 移除 name 变量对应的值两边的空格,并输 ...

  7. 【转载】JavaScript中的属性:如何遍历属性

    转载自:http://www.cnblogs.com/ziyunfei/archive/2012/11/03/2752905.html 在JavaScript中,遍历一个对象的属性往往没有在其他语言中 ...

  8. C++ code:数值计算之辛普生(Simpson)法求解积分问题

  9. Laravel框架中的event事件操作

    有时候当我们单纯的看 Laravel 手册的时候会有一些疑惑,比如说系统服务下的授权和事件,这些功能服务的应用场景是什么,其实如果没有经历过一定的开发经验有这些疑惑是很正常的事情,但是当我们在工作中多 ...

  10. hdu3415 单调队列模板题

    比较裸的单调队列 先求前缀和,枚举所有结束位置1~n+k即可 #include<iostream> #include<cstdio> #include<cstring&g ...