【题目】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. Spring管理过滤器:org.springframework.web.filter.DelegatingFilterProxy

    配置web.xml <filter>        <filter-name>springSecurityFilterChain</filter-name>     ...

  2. String、StringBuilder与StringBuffer的区别

    1.String类是public.final修饰的. 在Java中,被final修饰的类是不允许被继承的,并且String它的成员方法都默认为final方法. 查看源码得知,String类其实是通过c ...

  3. PAT 甲级 1020 Tree Traversals

    https://pintia.cn/problem-sets/994805342720868352/problems/994805485033603072 Suppose that all the k ...

  4. 将oracle数据库表使用命令的形式导入到excle文件中 亲测可用!

    main.sql 中的代码 set markup html on entmap ON spool on preformat off spool D:\新建文件夹\mick\tables.xls @ge ...

  5. c 用指针操作结构体数组

    重点:指针自加,指向下一个结构体数组单元 #include <stdio.h> #include <stdlib.h> #include <string.h> #d ...

  6. 以太网帧,IP,TCP,UDP首部结构

    1.以太网帧的格式 以太网封装格式 2.IP报头格式 IP是TCP/IP协议簇中最为重要的协议.所有的TCP,UDP, ICMP和IGMP数据都以IP数据报格式传输.IP提供的是不可靠.无连接的协议. ...

  7. Guide: Solr performance tuning--转载

    原文地址:http://h3x.no/2011/05/10/guide-solr-performance-tuning Introduction I have for the last year be ...

  8. 利用JavaFX访问MySQL数据库

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

  9. 部分NodeJs

    一.cnmp的操作: 1.cnmp info jquery查询jquery的版本: 2.cnmp install jquery@1.11.1:安装: 3.cnmp list查询所有下载的内容: 4.c ...

  10. IOS8模糊毛玻璃的效果UIVisualEffectView

    UIVisualEffectView实现两种模糊效果:UIBlurEffect 和 UIVibrancyEffect 两者都是继承自UIView,前者放在任意的View里边都能对下册的视图渲染出模糊效 ...