CF915E Physical Education Lessons 动态开点线段树
题目链接
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 动态开点线段树的更多相关文章
- codeforces 893F - Physical Education Lessons 动态开点线段树合并
https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的 ...
- codeforces 915E - Physical Education Lessons 动态开点线段树
题意: 最大$10^9$的区间, $3*10^5$次区间修改,每次操作后求整个区间的和 题解: 裸的动态开点线段树,计算清楚数据范围是关键... 经过尝试 $2*10^7$会$MLE$ $10^7$会 ...
- CF915E Physical Education Lessons(珂朵莉树)
中文题面 据说正解是动态开点线段树而且标记也不难下传的样子 然而这种区间推平的题目还是喜欢写珂朵莉树啊……码量小…… 虽然真要构造的话随便卡…… //minamoto #include<cstd ...
- Physical Education Lessons CodeForces - 915E (动态开点线段树)
Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...
- CF915E Physical Education Lessons
题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...
- 【题解】Luogu CF915E Physical Education Lessons
原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...
- [2016湖南长沙培训Day4][前鬼后鬼的守护 chen] (动态开点线段树+中位数 or 动规 or 贪心+堆优化)
题目大意 给定一个长度为n的正整数序列,令修改一个数的代价为修改前后两个数的绝对值之差,求用最小代价将序列转换为不减序列. 其中,n满足小于500000,序列中的正整数小于10^9 题解(引自mzx神 ...
- [bzoj 3531][SDOI2014]旅行(树链剖分+动态开点线段树)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3531 分析: 对于每个颜色(颜色<=10^5)都建立一颗线段树 什么!那么不是M ...
- 【BZOJ-4636】蒟蒻的数列 动态开点线段树 ||(离散化) + 标记永久化
4636: 蒟蒻的数列 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 247 Solved: 113[Submit][Status][Discuss ...
随机推荐
- Cpp读文件、CString转String、String转CString
场景 C++读取文件 技术点 读取文件 fstream提供了三个类,用来实现c++对文件的操作.(文件的创建.读.写). ifstream -- 从已有的文件读入 ofstream -- 向文件写内容 ...
- python内置模块之unittest测试(五)
系列文章 python模块分析之random(一) python模块分析之hashlib加密(二) python模块分析之typing(三) python模块分析之logging日志(四) pytho ...
- k64 datasheet学习笔记1---概述
1.前言 k64 datasheet描述了Freescale MCU的特性.架构和编程模型,主要是面向使用MCU的系统架构和软件应用开发人员. 2.模块划分 datasheet主要按功能对模块进行划分 ...
- UML和模式应用4:初始阶段(1)--概述
1.前言 UP开发包括四个阶段:初始阶段.细化阶段.构建阶段.移交阶段: 初始阶段是项目比较简短的起始步骤,主要目的是收集足够的信息来建立共同设想,调查项目的总体目标和可行性,确定是否值得进一步深入. ...
- jquery学习集合
跳转网页:$(location).attr('href', '/index');
- 擅于使用JS的eval方法
样例如下: var appsDetails = {“app1”:"", “app2”:"", “app3”:"", “app4”:" ...
- php中相对路径和绝对路径如何使用(详解)
目录 一.总结 一句话总结: 1.php中用用“/”表示根目录么? 2.什么符号表示当前目录(asp,jsp,php都一样)? 3.php中如何使用$_SERVER['DOCUMENT_ROOT']做 ...
- 转:vue+element实现树形组件
项目中需要用到树形组件,在网上发现一个用vue+element实现的树形组件,现在记录下: demo地址:https://github.com/wilsonIs/vue-treeSelect
- linux java报错汇总
一:♦linux 下javac 编译报 需要class, interface 或enum错误 ♦解析时已到达文件结尾 原因:大括号补匹配 //注意看报警提示
- iOS中按钮点击事件处理方式
写在前面 在iOS开发中,时常会用到按钮,通过按钮的点击来完成界面的跳转等功能.按钮事件的实现方式有多种,其中 较为常用的是目标-动作对模式.但这种方式使得view与controller之间的耦合程度 ...