【CodeForces】915 E. Physical Education Lessons 线段树
【题目】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 线段树的更多相关文章
- 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 915E】 Physical Education Lessons
[题目链接] 点击打开链接 [算法] 线段树,注意数据量大,要动态开点 [代码] #include<bits/stdc++.h> using namespace std; ; ,root ...
- Physical Education Lessons CodeForces - 915E (动态开点线段树)
Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...
- Codeforces 915E. Physical Education Lessons(动态开点线段树)
E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...
- CF915E Physical Education Lessons 动态开点线段树
题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...
- 线段树 离散化 E. Infinite Inversions E. Physical Education Lessons
题目一:E. Infinite Inversions 这个题目没什么思维量,还比较简单,就是离散化要加上每一个值的后面一个值,然后每一个值放进去的不是1 ,而是这个值与下一个点的差值. 因为这个数代表 ...
- E. Physical Education Lessons 动态开辟线段树区间更新
E. Physical Education Lessons time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces 915E Physical Education Lessons
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
- CF915E Physical Education Lessons
题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...
随机推荐
- Qt使用QNetworkAccessManager实现Http操作
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt使用QNetworkAccessManager实现Http操作 本文地址:http ...
- jetty之maven配置
<!-- jetty 插件配置 --><plugin> <groupId>org.mortbay.jetty</groupId> <artifac ...
- sysbench 环境安装,压测mysql
源码路径:https://github.com/akopytov/sysbench 版本linux 6.8sysbench 0.5mysql 5.6.29 1.安装pip略 2.pip 安装bzr p ...
- node.js入门(一)
NodeJS是一个使用了Google高性能V8引擎的服务器端JavaScript实现.它提供了一个(几乎)完全非阻塞I/O栈,与JavaScript提供的闭包和匿名函数相结合,使之成为编写高吞吐 量网 ...
- py27使用redis
1.安装redis pip install redis 转载请注明博客出处:http://www.cnblogs.com/cjh-notes/
- 关于ADO一个容易被忽视的问题!UpdateBatch [问题点数:0分]
这是一个常见但容易被忽视的问题,旧贴有问及但没答案,因此提高分数.相信大家常这样使用Cache模式:ADOConnection1.BeginTrans;Try ADODataSet1.UpdateBa ...
- Flume日志收集系统架构详解--转
2017-09-06 朱洁 大数据和云计算技术 任何一个生产系统在运行过程中都会产生大量的日志,日志往往隐藏了很多有价值的信息.在没有分析方法之前,这些日志存储一段时间后就会被清理.随着技术的发展和 ...
- request之setAtrribute
当在servlet中有request.SetAtrribute("AtriruteName",AtrributeValue)语句时,在jsp页面获取AtrributeValue有两 ...
- MySQL join 使用方法
JOIN 按照功能大致分为如下三类: INNER JOIN(内连接,或等值连接):取得两个表中存在连接匹配关系的记录. LEFT JOIN(左连接):取得左表(table1)完全记录,即是右表(tab ...
- P2764 最小路径覆盖问题(网络流24题之一)
题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...