题目链接

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. nodejs的process模块如何获取其他进程的pid

    var cmd=process.platform=='win32'?'tasklist':'ps aux'; var exec = require('child_process').exec; var ...

  2. Python poll IO多路复用

    一.poll介绍 poll本质上和select没有区别,只是没有了最大连接数(linux上默认1024个)的限制,原因是它基于链表存储的. 本人的另一篇博客讲了 python  select : ht ...

  3. zabbix3.0.4使用shell脚本和zabbix自带模板两种方法添加对指定进程和端口的监控

    zabbix3.0.4添加对进程的监控: 方法一:通过自定义命令进行监控 主要思路: 通过 ps -ef|grep sdk-push-1.0.0.jar |grep -v grep|wc -l 这个命 ...

  4. Day5-----------------------系统监控

    1.top 命令 查看终端信息 who 显示终端用户有哪些 bash 开启终端进程 PID:进程身份证 buffer:缓冲区 cache:高速缓存 进程:动起来的文件,CPU调用运行的过程 2.fre ...

  5. jQuery实现鼠标点击div外的地方div隐藏消失的效果

    css部分: <style type="text/css"> .pop { width:200px; height:130px; background:#080;} & ...

  6. IE6下select被这罩住

    在我们做弹出遮罩层时经常遇到这种问题,就是select被这罩住不兼容IE6,其实解决这种问题并不难,只要掌握住原理就挺简单的. 首先就是当遮罩层出现时select要暂时隐藏,但是不能用display: ...

  7. 单元测试-代码覆盖率 EclEmma

    1. EclEmma的介绍 EclEmma是一个开源的软件测试工具,可以在编码过程中查看代码调用情况.也可以检测单覆盖率. 2. Eclipse下EclEmma安装 1. 选择Help->Ecl ...

  8. hdu4052矩形面积并

    建模需要注意下细节,,这是做扫描线的惯例,就是最好把模型建立在笛卡尔坐标系上 剩下的看链接和注释https://blog.csdn.net/shiqi_614/article/details/7983 ...

  9. BOM下的属性和方法---下

    继续BOM下的属性和方法---上 代码示例(亲测)2:   <title>location对象的属性</title> <script> //服务器环境我再此次演示中 ...

  10. windows Service程序的安装、启动、卸载命令

    安装:%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe ServiceTest.exe 启动:Net Start serv ...