【题目】E. Physical Education Lessons

【题意】10^9范围的区间覆盖,至多3*10^5次区间询问。

【算法】线段树

【题解】每次询问至多增加两段区间,提前括号分段后线段树。

#include<cstdio>
#include<cctype>
#include<set>
#include<algorithm>
using namespace std;
int read(){
char c;int s=,t=;
while(!isdigit(c=getchar()))if(c=='-')t=-;
do{s=s*+c-'';}while(isdigit(c=getchar()));
return s*t;
}
const int maxn=;
struct tree{int l,r,delta,sum,p;}t[maxn*];//
int au[maxn],av[maxn],k[maxn],a[maxn],n,q,tot;
set<int>s;
void build(int k,int l,int r){
t[k].l=l;t[k].r=r;t[k].delta=-;
if(l==r){t[k].p=t[k].sum=a[l]-a[l-];return;}
int mid=(l+r)>>;
build(k<<,l,mid);build(k<<|,mid+,r);
t[k].p=t[k<<].p+t[k<<|].p;
t[k].sum=t[k<<].sum+t[k<<|].sum;
}
void modify(int k,int x){t[k].sum=t[k].p*x;t[k].delta=x;}
void down(int k){
if(~t[k].delta){
modify(k<<,t[k].delta);modify(k<<|,t[k].delta);
t[k].delta=-;
}
}
void up(int k){t[k].sum=t[k<<].sum+t[k<<|].sum;}
void cover(int k,int l,int r,int x){
if(l<=t[k].l&&t[k].r<=r){modify(k,x);return;}
down(k);
int mid=(t[k].l+t[k].r)>>;
if(l<=mid)cover(k<<,l,r,x);
if(r>mid)cover(k<<|,l,r,x);
up(k);
}
int main(){
n=read();q=read();
for(int i=;i<=q;i++){
au[i]=read();av[i]=read();k[i]=read();
s.insert(au[i]-);s.insert(av[i]);
}
if(*s.begin()==)s.erase(s.begin());
s.insert(n);
for(set<int>::iterator it=s.begin();it!=s.end();it++){
a[++tot]=*it;
}
for(int i=;i<=q;i++){
au[i]=lower_bound(a+,a+tot+,au[i])-a;
av[i]=lower_bound(a+,a+tot+,av[i])-a;
}
n=tot;
build(,,n);
for(int i=;i<=q;i++){
cover(,au[i],av[i],k[i]-);
printf("%d\n",t[].sum);
}
return ;
}

【CodeForces】915 E. 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 915E】 Physical Education Lessons

    [题目链接] 点击打开链接 [算法] 线段树,注意数据量大,要动态开点 [代码] #include<bits/stdc++.h> using namespace std; ; ,root ...

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

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

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

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

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

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

  6. 线段树 离散化 E. Infinite Inversions E. Physical Education Lessons

    题目一:E. Infinite Inversions 这个题目没什么思维量,还比较简单,就是离散化要加上每一个值的后面一个值,然后每一个值放进去的不是1 ,而是这个值与下一个点的差值. 因为这个数代表 ...

  7. E. Physical Education Lessons 动态开辟线段树区间更新

    E. Physical Education Lessons time limit per test 1 second memory limit per test 256 megabytes input ...

  8. Codeforces 915E Physical Education Lessons

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

  9. CF915E Physical Education Lessons

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

随机推荐

  1. 读着读着《构建之法》(Build To Win) 越精神的白雪儿的思考

    哲学家的宗旨是:我思,故我在 科学家的宗旨是:我发现,故我在 工程师的宗旨是:我构建,故我在 ——<工程学--无尽的前沿> 序言:珍惜角色“人”,注重实践“物” <构建之法>, ...

  2. 【Nginx】转:Nginx try_files

    原来的配置是这样的: location / { try_files $uri $uri/ /index.php; index index.html index.htm index.php; } loc ...

  3. POJ3709_K-Anonymous Sequence

     题意很简单,给你若干个数字,你需要减去一些数字,使得在数列中的每个数字出现的次数不少于k次. 一开始我们都会想到是用DP,于是很快我们就可以得出状态为搞定前面i个数所需要花费的最小代价用f[i]表示 ...

  4. json 当集合类型的字符串变成集合时候 里面有map类型的转换操作

  5. 利用JavaFX访问MySQL数据库

    1. 创建数据库表 create table Course( courseId char(5), subjectId char(4) not null, courseNumber integer, t ...

  6. [BZOJ3223]文艺平衡树 无旋Treap

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MB Description 您需要写一种数据结构(可参考题目标题),来维护一个 ...

  7. 创建Django的App

    一. 新建1个App,命令:python manage.py startapp lib 1. 打开终端 2. 新建 3. 把业务代码放到每一个APP里面就更专业了. 修改urls里面的代码如下: 运行 ...

  8. CF878C Tournament set 图论

    题面 题面 题解 如果2个人可以互相战胜,那么我们连一条无向边,于是最后会剩下t个联通块,其中每对联通块之间都有严格的大小关系(a.max < b.min),因此我们每插入一个点就相当于合并一段 ...

  9. 【Luogu1912】【NOI2009】诗人小G(动态规划)

    [Luogu1912][NOI2009]诗人小G(动态规划) 题面 洛谷 题解 原来\(NOI\)这么多神仙题... 考虑一个极其明显的\(dp\) 设\(f[i]\)表示前\(i\)个句子产生的最小 ...

  10. 【CF700E】Cool Slogans(后缀自动机)

    [CF700E]Cool Slogans(后缀自动机) 题面 洛谷 CodeForces 题解 构建后缀自动机,求出后缀树 现在有个比较明显的\(dp\) 设\(f[i]\)表示从上而下到达当前点能够 ...