【题目链接】

点击打开链接

【算法】

线段树,注意数据量大,要动态开点

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = ; int n,q,l,r,opt,size = ,root = ;
struct Node {
int lc,rc,tag,sum;
} Tree[MAXN]; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline void push_up(int root) {
Tree[root].sum = Tree[Tree[root].lc].sum + Tree[Tree[root].rc].sum;
}
inline void push_down(int l,int r,int root) {
int mid = (l + r) >> ;
if (Tree[root].tag != -) {
if (!Tree[root].lc) Tree[root].lc = ++size;
if (!Tree[root].rc) Tree[root].rc = ++size;
Tree[Tree[root].lc].tag = Tree[Tree[root].rc].tag = Tree[root].tag;
Tree[Tree[root].lc].sum = Tree[root].tag * (mid - l + );
Tree[Tree[root].rc].sum = Tree[root].tag * (r - mid);
Tree[root].tag = -;
}
}
inline void modify(int &root,int l,int r,int ql,int qr,int val) {
int mid;
if (!root) root = ++size;
if (l == ql && r == qr) {
Tree[root].sum = val * (r - l + );
Tree[root].tag = val;
return;
}
push_down(l,r,root);
mid = (l + r) >> ;
if (mid >= qr) modify(Tree[root].lc,l,mid,ql,qr,val);
else if (mid + <= ql) modify(Tree[root].rc,mid+,r,ql,qr,val);
else {
modify(Tree[root].lc,l,mid,ql,mid,val);
modify(Tree[root].rc,mid+,r,mid+,qr,val);
}
push_up(root);
} int main() { read(n); read(q);
while (q--) {
read(l); read(r); read(opt);
if (opt == ) modify(root,,n,l,r,);
else modify(root,,n,l,r,);
writeln(n - Tree[].sum);
} return ; }

【Codeforces 915E】 Physical Education Lessons的更多相关文章

  1. Codeforces 915 E Physical Education Lessons

    题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...

  2. 【CodeForces】915 E. Physical Education Lessons 线段树

    [题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...

  3. Codeforces 915E Physical Education Lessons

    原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...

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

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

  5. 【题解】Luogu CF915E Physical Education Lessons

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

  6. Codeforces 915E. Physical Education Lessons(动态开点线段树)

    E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...

  7. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  8. CF915E Physical Education Lessons 动态开点线段树

    题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...

  9. CF915E Physical Education Lessons

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

随机推荐

  1. kafka直连方式消费多个topic

    一个消费者组可以消费多个topic,以前写过一篇一个消费者消费一个topic的,这次的是一个消费者组通过直连方式消费多个topic,做了小测试,结果是正确的,通过查看zookeeper的客户端,zoo ...

  2. [luoguP1773] 符文之语_NOI导刊2010提高(02)(DP)

    传送门 f[i][j]表示前i个数余数为j的最优解 sum[i][j]表示字符串i~j所构成的数 #include <cstdio> #include <cstring> #d ...

  3. RedisDesktopManager 踩坑之旅

    虚拟机上装了redis, 本地Windows的RedisDesktopManager  connect failed. 解决方法: 1.修改 redis.conf 文件 bind 127.0.0.1 ...

  4. python学习之-- random模块

    random模块random.random():随机打印一个小数random.randint(1,10):随机打印1-10之间的任意数字(包括1和10)random.randrange(1,10):随 ...

  5. Spring4MVC 请求参数映射和Content-type

    目录 前言 不使用注解(不传则为null) 基本数据类型和日期类型 自定义类型POJO @PathVariable注解 @RequestParam 注解 @RequestBody注解 复杂对象Arra ...

  6. 转 asterisk app命令中文翻译

    常规指令 Authenticate:鉴别用户 VMAuthenticate:根据“voicemail.conf”鉴别用户 Curl:接受外接URLs的修复.支持POSTing DUNDiLookup: ...

  7. grunt安装,配置记录

    进了新的公司,需要重构一个项目,从头开始.本人患懒癌已久,一直没有写博客的打算,也是因为资质还比较浅,写不出什么富有涵养的内容,后来想了想,就当自己的笔记吧.这次从新开始,未尝不是一个博客开始的好时机 ...

  8. Using DTrace to Profile and Debug A C++ Program

    http://www.oracle.com/technetwork/server-storage/solaris/dtrace-cc-138561.html

  9. 元数据的概念以及相关的操作os模块、shutil模块

    查看文件的元数据 stat [OPTION]… FILE… OPTION: -f 输出文件系统的状态,而非文件的状态 -t 显示简要格式的文件元数据信息 FILE:可同时查看多个文件的元数据信息,多个 ...

  10. php monolog 的写日志到unix domain socket 测试终于成功

    在另外一个客户端执行 php s.php后, 通过nc -lU /tmp/tg.sck 建立的unix domain socket 有接收到消息. <?php require 'vendor/a ...