【Codeforces 915E】 Physical Education Lessons
【题目链接】
【算法】
线段树,注意数据量大,要动态开点
【代码】
#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的更多相关文章
- Codeforces 915 E Physical Education Lessons
题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...
- 【CodeForces】915 E. Physical Education Lessons 线段树
[题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...
- Codeforces 915E Physical Education Lessons
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
- Physical Education Lessons CodeForces - 915E (动态开点线段树)
Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...
- 【题解】Luogu CF915E Physical Education Lessons
原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...
- Codeforces 915E. Physical Education Lessons(动态开点线段树)
E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- CF915E Physical Education Lessons 动态开点线段树
题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...
- CF915E Physical Education Lessons
题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...
随机推荐
- [HDU2157]How many ways??(DP + 矩阵优化)
传送门 k < 20 k这么小,随便dp一下就好了... dp[i][j][k]表示从i到j经过k个点的方案数 4重循环.. 但是如果k很大就不好弄了 把给定的图转为邻接矩阵,即A(i,j)=1 ...
- 海战(洛谷 P1331)
题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...
- HTML介绍&常用的标签
HTML介绍 1. web服务器本质 import socket s = socket.socket() s.bind(('127.0.0.1', 8080)) s.listen(5) while T ...
- Spring Cloud(8):Sleuth和Zipkin的使用
场景: 某大型电商网站基于微服务架构,服务模块有几十个. 某天,测试人员报告该网站响应速度过慢.排除了网络问题之后,发现很难进一步去排除故障. 那么:如何对微服务的链路进行监控呢? Sleuth: 一 ...
- 转:Linux中的内存管理
前一段时间看了<深入理解Linux内核>对其中的内存管理部分花了不少时间,但是还是有很多问题不是很清楚,最近又花了一些时间复习了一下,在这里记录下自己的理解和对Linux中内存管理的一些看 ...
- 使用SpringMVC @Async异步执行方法的笔记 (转载)
原文:http://blog.csdn.net/yuwenruli/article/details/8514393 测试代码: @RunWith(SpringJUnit4ClassRunner.cla ...
- Android中传递对象的三种方法
Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! Android中,Activity和Fragment之间传递对象,可以通过将对象序列化并存入Bundle或者I ...
- ubuntu磁盘分区和挂载
- Deepin-安装node
点击下载:Linux x64 文件解压: 方式1$xz -d file.tar.xz $tar -xvf file.tar 方式2 $tar xvJf file.tar.xz 解压后,把它移动到:/u ...
- MyBatis -- sql映射文件具体解释
MyBatis 真正的力量是在映射语句中. 和对等功能的jdbc来比价,映射文件节省非常多的代码量. MyBatis的构建就是聚焦于sql的. sql映射文件有例如以下几个顶级元素:(按顺序) cac ...