【题目链接】

点击打开链接

【算法】

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

【代码】

#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. 机器学习基础-Logistic回归1

    利用Logistic回归进行分类的主要思想是:根据现有数据对分类边界线建立回归公式,以此进行分类. 训练分类器时的做法就是寻找最佳拟合参数,使用的时最优化算法. 优点:计算代价不高,利于理解和实现. ...

  2. C 题 KMP中next[]问题

    题目大意: 找到能够进行字符串匹配的前缀 这题只要一直求next,直到next为0停止,记得答案是总长减去next的长度 #include <iostream> #include < ...

  3. [luoguP1772] [ZJOI2006]物流运输(DP + spfa)

    传送门 预处理cost[i][j]表示从第i天到第j天起点到终点的最短距离 f[i]表示前i天到从起点到终点的最短距离 f[0] = -K f[i] = min(f[i], f[j - 1] + co ...

  4. 巴蜀4384 -- 【模拟试题】作诗(Poetize)

    Description 神犇SJY虐完HEOI之后给傻×LYD出了一题:SHY是T国的公主,平时的一大爱好是作诗.由于时间紧迫,SHY作完诗之后还要虐OI,于是SHY找来一篇长度为N的文章,阅读M次, ...

  5. 【BZOJ3626】LCA(树上差分,树链剖分)

    题意:给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1.设dep[i]表示点i的深度,LCA(i,j)表示i与j的最近公共祖先.有q次询问,每次询问给 ...

  6. CF830B:Cards Sorting

    对叠放着的n张牌,第i张牌写有数字Ai,进行操作:将牌堆顶的牌取出,若是当前牌堆最小值就扔掉,否则放到牌堆底,求牌堆空时操作次数. 怎么看怎么像约瑟夫..不过约瑟夫DP我不太熟,于是就yy了一下 “当 ...

  7. UVA 10200 Prime Time【暴力,精度】

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  8. SOJ 4482 忽悠大神【最小生成树】

    题目链接: http://acm.scu.edu.cn/soj/problem.action?id=4482 题意: 给定边权和点权,从一个点出发并回到该点,减少尽量多的边,每路过点和边都要把权重加到 ...

  9. Ubuntu更换主板之后 网络重新配置

    Ubuntu更换主板之后,网络不能用,需要重新配置 1.  首要要查看新主板的mac地址, dmesg | grep eth 2.  修改网络信息,该配置文件是/etc/udev/rules.d, 文 ...

  10. HadoopMapReduce运行机制

    1.map方法读取一个文件的一行记录进行分析,  输入:LongWritable(当前读取的文件位置), Text(内容) 2.map将读取到的信息进行分类,输入Context  (键值对)  ;作为 ...