【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可不希望被开除,他想知道到期末还 ...
随机推荐
- ZOJ 2588 求割边问题
题目链接:http://vjudge.net/problem/viewProblem.action?id=14877 题目大意: 要尽可能多的烧毁桥,另外还要保证图的连通性,问哪些桥是绝对不能烧毁的 ...
- BZOJ 1924: [Sdoi2010]所驼门王的宝藏 【tarjan】
Description 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为“先 知”的Alpaca L. Sotomon 是这个家族的领袖,外人也称其为“所驼门王”.所 驼门王毕生致力于维 ...
- BZOJ1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草
数轴上n<=1000个点,从p出发以任意顺序走到所有的点,求到达每个点的时间之和的最小值. 好题!看起来水水的实际易错! 显然的结论是经过一个区间点之后肯定落在左端点或右端点上,谁没事最后还往中 ...
- ibatis中的xml配置文件
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMap PUBLIC "-/ ...
- Python()- 面向对象三大特性----多态
多态: python 生来支持多态白话:一种事物的多种形态 (动物可以继承给狗,也可以继承给猫) class Animal: pass class Dog(Animal): def attack(se ...
- iOS tableview上textView在编辑状态时,tableview自动上移的功能
在viewcognroller中,添加tableview时, tableview中cell上的textField如果吊起键盘时,tableview时可以自动上移,但是如果是textView吊起键盘,t ...
- [Noip复习知识点][个人向]Zackzh
只是列列一些要复习的,努力复习吧,有种noip退役的赶脚. 一.模拟 (这你也不会?退役吧) 二.DP 1.基础dp 2.区间dp 3.状压dp 4.树形dp 6.概率(期望)dp 7.环形dp 8. ...
- IDEA下使用protobuf2(java)
目录 一.介绍 二.特点 三.结构 四.选择版本 五.Intellij IDEA中使用Protobuf 1.下载个protoc.exe 2.编辑个.proto文件 3.将.proto文件转成Java类 ...
- http://www.ybtsoft.com/
http://www.ybtsoft.com/ 可视化作流建模 http://www.ybtsoft.com/t3/bpm/ 慧都控件网 写一本关于互联网商业变现的书
- oracle dtrace for linux
https://docs.oracle.com/cd/E37670_01/E37355/html/ol_config_dtrace.html#