【题目】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. 使用rand替换random模块

    random模块使用相同的种子,在不同的进程中会出现相同的结果. rand的模块使用不同的种子,在不同的进程中不会出现相同的结果. 2个模块都是erlang自带的. 然后erlang在文档里面注明推荐 ...

  2. 微信小程序 跳坑

    http://www.wxapp-union.com/forum.php?mod=viewthread&tid=3270

  3. 【Quartz.Net】.net 下使用Quartz.Net

    Quartz.net是作业调度框架 1. 项目中添加quartz.net的引用(这里使用nuget管理) 新建一个类TimingJob,该类主要用于实现任务逻辑   using Quartz; usi ...

  4. CTSC2012-Cheat

    题意 给出一些母01串,多次询问,每次询问一个01串,问一个最大的\(L\),使得可以在询问串中选出若干个不相交的,长度大于等于\(L\)的子串,这些子串都在母串中出现过,且子串的长度和大于等于询问串 ...

  5. LeetCode 696. Count Binary Substrings

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

  6. PL/SQL中复制粘贴表结构信息

    1.打开下图中的Tables文件夹 2.查找要找的表 3.右键单击找到的表—>Describe 4.复制所需的数据到EXCEL表中

  7. [二十一]SpringBoot 之 导入xml配置

    SpringBoot理念就是零配置编程,但是如果绝对需要使用XML的配置,我们建议您仍旧从一个@Configuration类开始,你可以使用@ImportResouce注解加载XML配置文件,我拿一个 ...

  8. 51NOD 1559:车和矩形——题解

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1559 波雷卡普有一个n×m,大小的棋盘,上面有k个车.他又放了q个矩形在 ...

  9. linux内核分析 第三周 构造一个简单的Linux系统MenuOS

    一.计算机的三个法宝 存储程序计算机,函数调用堆栈,中断二.操作系统的两把剑:1.中断上下文的切换,保存现场和恢复现场2.进程上下文的切换. 三.linux内核源代码的分析: ·arch/目录保存支持 ...

  10. Codeforces Round #358 (Div. 2) A B C 水 水 dfs序+dp

    A. Alyona and Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...