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 ... 
随机推荐
- Linux注销&登陆
			⒈注销 ①在命令行使用logout,此指令在图形界面无效. 
- Pytorch入门之VAE
			关于自编码器的原理见另一篇博客 : 编码器AE & VAE 这里谈谈对于变分自编码器(Variational auto-encoder)即VAE的实现. 1. 稀疏编码 首先介绍一下“稀疏编码 ... 
- ubuntu16.04安装opencv2.4.13
			1.更新 sudo apt-get update sudo apt-get upgrade 2.安装关联库 2.1 搭建C/C++编译环境 sudo apt-get install build-ess ... 
- BN讲解(转载)
			本文转载自:http://blog.csdn.net/shuzfan/article/details/50723877 本次所讲的内容为Batch Normalization,简称BN,来源于< ... 
- Linux 获取设备树源文件(DTS)里描述的资源【转】
			转自:http://www.linuxidc.com/Linux/2013-07/86839.htm 转自:http://blog.sina.com.cn/s/blog_636a55070101mce ... 
- mysql数据库查询库中所有表所占空间大小
			SELECT CONCAT(table_schema,'.',table_name) AS 'TABLE_NAME', CONCAT(, ),'M') AS 'ROW_SIZE', CONCAT( ) ... 
- javascrip学习之 数据类型和变量
			JavaScript 是脚本语言.是一种轻量级的编程语言.是可插入 HTML 页面的编程代码,可由所有的现代浏览器执行. JavaScript的语法和Java语言类似,每个语句以;结束,语句块用{.. ... 
- 执行update语句mysql5.6报错ERROR 1292 (22007): Truncated incorrect DOUBLE value: '糖糖的坤大叔'
			执行修改语句update tbl_user_details set nickname=CONCAT("用户",yunva_id) where nickname = yunva_id ... 
- 深入理解【缺页中断】及FIFO、LRU、OPT这三种置换算法
			缺页中断(英语:Page fault,又名硬错误.硬中断.分页错误.寻页缺失.缺页中断.页故障等)指的是当软件试图访问已映射在虚拟地址空间中,但是目前并未被加载在物理内存中的一个分页时,由中央处理器的 ... 
- Numpy中stack(),hstack(),vstack()函数详解
			一`.stack 按指定维度堆叠数组. stack(a, b) 维度计算 axis=0: 2*m*n axis=1: m*2*n axis=-1: m*n*2 a = np.arange( ... 
