题目链接

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. python3之requests

    1.requests简介 requests是通过urllib3实现自动发送HTTP/1.1请求,它能轻松的实现cookies,登陆验证,代理设置等操作. Python内置的urllib模块,用于访问网 ...

  2. Windows Server2008各版本区别

    Windows Server 2008 是专为强化下一代网络.应用程序和 Web 服务的功能而设计,是有史以来最先进的 Windows Server 操作系统.拥有 Windows Server 20 ...

  3. machine_desc结构体【转】

    转自:http://blog.csdn.net/myarrow/article/details/8609564 1. 简介 内核提供了一个重要的结构体struct machine_desc ,这个结构 ...

  4. nodejs 在线学习课堂

    http://ww***/class/5359f6f6ec7452081a7873d8

  5. jdk8系列二、jdk8方法引用、重复注解、更好的类型推断、新增注解

    一.方法引用 方法引用使得开发者可以直接引用现存的方法.Java类的构造方法或者实例对象.方法引用和Lambda表达式配合使用,使得java类的构造方法看起来紧凑而简洁,没有很多复杂的模板代码. 方法 ...

  6. tomcat jsp页面乱码解决

    浏览器接收服务器响应的中文参数: JSP页面中告诉浏览器使用什么编码: <%@ page language="java" contentType="text/htm ...

  7. 028_rync和inotify实现实时备份

    一.服务节点安装inotify-tools. 确保系统后以下输出=> [root@xxxx]# ll /proc/sys/fs/inotify/ total 0 -rw-r--r-- 1 roo ...

  8. Expm 3_2 寻找最邻近的点对

      [问题描述] 设p1=(x1,y1), p2=(x2,y2), … , pn=(xn,yn) 是平面上n个点构成的集合S,设计和实现找出集合S中距离最近点对的算法. 每一个格子最多只能存在一个点, ...

  9. Navicat Premium

    Navicat Premium Navicat Premium,一个专门用于操作各种数据库的工具,oracle,sql server,mysql,db2,access等等 下载链接:https://d ...

  10. Java基础96 ajax技术的使用

    本文知识点(目录): 1.ajax的概念   2.使用ajax技术获取服务端的数据_实例   3.使用ajax技术检查用户名是否已存在_实例   4.使用ajax技术验证登录页面的用户名和密码_实例 ...