【题目】E. Physical Education Lessons

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

【算法】线段树

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

  1. #include<cstdio>
  2. #include<cctype>
  3. #include<set>
  4. #include<algorithm>
  5. using namespace std;
  6. int read(){
  7. char c;int s=,t=;
  8. while(!isdigit(c=getchar()))if(c=='-')t=-;
  9. do{s=s*+c-'';}while(isdigit(c=getchar()));
  10. return s*t;
  11. }
  12. const int maxn=;
  13. struct tree{int l,r,delta,sum,p;}t[maxn*];//
  14. int au[maxn],av[maxn],k[maxn],a[maxn],n,q,tot;
  15. set<int>s;
  16. void build(int k,int l,int r){
  17. t[k].l=l;t[k].r=r;t[k].delta=-;
  18. if(l==r){t[k].p=t[k].sum=a[l]-a[l-];return;}
  19. int mid=(l+r)>>;
  20. build(k<<,l,mid);build(k<<|,mid+,r);
  21. t[k].p=t[k<<].p+t[k<<|].p;
  22. t[k].sum=t[k<<].sum+t[k<<|].sum;
  23. }
  24. void modify(int k,int x){t[k].sum=t[k].p*x;t[k].delta=x;}
  25. void down(int k){
  26. if(~t[k].delta){
  27. modify(k<<,t[k].delta);modify(k<<|,t[k].delta);
  28. t[k].delta=-;
  29. }
  30. }
  31. void up(int k){t[k].sum=t[k<<].sum+t[k<<|].sum;}
  32. void cover(int k,int l,int r,int x){
  33. if(l<=t[k].l&&t[k].r<=r){modify(k,x);return;}
  34. down(k);
  35. int mid=(t[k].l+t[k].r)>>;
  36. if(l<=mid)cover(k<<,l,r,x);
  37. if(r>mid)cover(k<<|,l,r,x);
  38. up(k);
  39. }
  40. int main(){
  41. n=read();q=read();
  42. for(int i=;i<=q;i++){
  43. au[i]=read();av[i]=read();k[i]=read();
  44. s.insert(au[i]-);s.insert(av[i]);
  45. }
  46. if(*s.begin()==)s.erase(s.begin());
  47. s.insert(n);
  48. for(set<int>::iterator it=s.begin();it!=s.end();it++){
  49. a[++tot]=*it;
  50. }
  51. for(int i=;i<=q;i++){
  52. au[i]=lower_bound(a+,a+tot+,au[i])-a;
  53. av[i]=lower_bound(a+,a+tot+,av[i])-a;
  54. }
  55. n=tot;
  56. build(,,n);
  57. for(int i=;i<=q;i++){
  58. cover(,au[i],av[i],k[i]-);
  59. printf("%d\n",t[].sum);
  60. }
  61. return ;
  62. }

【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. Qt使用QNetworkAccessManager实现Http操作

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt使用QNetworkAccessManager实现Http操作     本文地址:http ...

  2. jetty之maven配置

    <!-- jetty 插件配置 --><plugin> <groupId>org.mortbay.jetty</groupId> <artifac ...

  3. sysbench 环境安装,压测mysql

    源码路径:https://github.com/akopytov/sysbench 版本linux 6.8sysbench 0.5mysql 5.6.29 1.安装pip略 2.pip 安装bzr p ...

  4. node.js入门(一)

    NodeJS是一个使用了Google高性能V8引擎的服务器端JavaScript实现.它提供了一个(几乎)完全非阻塞I/O栈,与JavaScript提供的闭包和匿名函数相结合,使之成为编写高吞吐 量网 ...

  5. py27使用redis

    1.安装redis pip install redis 转载请注明博客出处:http://www.cnblogs.com/cjh-notes/

  6. 关于ADO一个容易被忽视的问题!UpdateBatch [问题点数:0分]

    这是一个常见但容易被忽视的问题,旧贴有问及但没答案,因此提高分数.相信大家常这样使用Cache模式:ADOConnection1.BeginTrans;Try ADODataSet1.UpdateBa ...

  7. Flume日志收集系统架构详解--转

     2017-09-06 朱洁 大数据和云计算技术 任何一个生产系统在运行过程中都会产生大量的日志,日志往往隐藏了很多有价值的信息.在没有分析方法之前,这些日志存储一段时间后就会被清理.随着技术的发展和 ...

  8. request之setAtrribute

    当在servlet中有request.SetAtrribute("AtriruteName",AtrributeValue)语句时,在jsp页面获取AtrributeValue有两 ...

  9. MySQL join 使用方法

    JOIN 按照功能大致分为如下三类: INNER JOIN(内连接,或等值连接):取得两个表中存在连接匹配关系的记录. LEFT JOIN(左连接):取得左表(table1)完全记录,即是右表(tab ...

  10. P2764 最小路径覆盖问题(网络流24题之一)

    题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...