原题传送门:CF915E Physical Education Lessons

前置芝士:珂朵莉树

窝博客里对珂朵莉树的介绍

没什么好说的自己看看吧

这道题很简单啊

每个操作就是区间赋值,顺带把总和修改一下,这样会快多了,所以我又成了洛咕最优解第二(好像比23forever dalao快,玄学???)

  1. #pragma GCC optimize("O3")
  2. #include <bits/stdc++.h>
  3. #define IT set<node>::iterator
  4. using namespace std;
  5. inline int read()
  6. {
  7. register int x=0,f=1;register char ch=getchar();
  8. while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  9. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  10. return x*f;
  11. }
  12. struct node
  13. {
  14. int l,r;
  15. mutable bool v;
  16. node(int L, int R=-1, bool V=0):l(L), r(R), v(V) {}
  17. bool operator<(const node& o) const
  18. {
  19. return l < o.l;
  20. }
  21. };
  22. set<node> s;
  23. int sum=0;
  24. IT split(int pos)
  25. {
  26. IT it = s.lower_bound(node(pos));
  27. if (it != s.end() && it->l == pos)
  28. return it;
  29. --it;
  30. int L = it->l, R = it->r;
  31. bool V = it->v;
  32. s.erase(it);
  33. s.insert(node(L, pos-1, V));
  34. return s.insert(node(pos, R, V)).first;
  35. }
  36. void assign_val(int l,int r,bool val)
  37. {
  38. IT itr = split(r+1), itl = split(l), it = itl;
  39. for( ;itl != itr; ++itl)
  40. sum-=itl->v*(itl->r-itl->l+1);
  41. s.erase(it,itr);
  42. s.insert(node(l,r,val));
  43. sum+=val*(r-l+1);
  44. }
  45. int main()
  46. {
  47. int n=read(),m=read();
  48. s.insert(node(1,n,1));
  49. sum=n;
  50. while(m--)
  51. {
  52. int l=read(),r=read(),op=read();
  53. if(op==1)
  54. assign_val(l,r,0);
  55. else
  56. assign_val(l,r,1);
  57. printf("%d\n",sum);
  58. }
  59. return 0;
  60. }

【题解】Luogu CF915E Physical Education Lessons的更多相关文章

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

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

  2. CF915E Physical Education Lessons

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

  3. CF915E Physical Education Lessons 珂朵莉树

    问题描述 CF915E LG-CF915E 题解 \(n \le 10^9\) 看上去非常唬人. 但是这种区间操作的题,珂朵莉树随便跑啊. \(\mathrm{Code}\) #include< ...

  4. CF915E Physical Education Lessons(珂朵莉树)

    中文题面 据说正解是动态开点线段树而且标记也不难下传的样子 然而这种区间推平的题目还是喜欢写珂朵莉树啊……码量小…… 虽然真要构造的话随便卡…… //minamoto #include<cstd ...

  5. 【CodeForces】915 E. Physical Education Lessons 线段树

    [题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...

  6. Codeforces 915E Physical Education Lessons

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

  7. Codeforces 915 E Physical Education Lessons

    题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...

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

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

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

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

随机推荐

  1. vue使用md5加密

    import crypto from 'crypto' export default { name: 'HelloWorld', data () { return { msg: 'Welcome to ...

  2. Amber TUTORIAL B5: Simulating the Green Fluorescent Protein

    Section 1: Preparing the PDB file 1EMA是本次教程所用的pdb,可以在PDB数据库下载. pdb4amber -i 1EMA.pdb -o gfp.pdb --dr ...

  3. 数据加密之MD5加密

    MD5是一个安全的散列算法,有两个特点:1.输入两个不同的明文(一段原始的数字信息)不会得到相同的输出值2.根据输出值,不能得到原始的明文,即过程不可逆所以要解密MD5没有现成的算法,只能用穷举法,把 ...

  4. Thinkphp 3.2 验证码图片显示错误解决方法

    在调用验证码之前加上 ob_clean(); 不显示验证码的代码: public function verify(){ $verify = new \Think\Verify(); $verify-& ...

  5. CSU 1857 Crash and Go(relians)(模拟)

    Crash and Go(relians) [题目链接]Crash and Go(relians) [题目类型]模拟 &题解: 这就是要严格的按照题意说的模拟就好了,也就是:每次添加进来一个圆 ...

  6. LeetCode108.将有序数组转换为二叉搜索树

    将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. 示例: 给定有序数组: [-10,-3,0, ...

  7. 如何使用Apache log4net库与ASP.NET MVC 5日志记录

    在运行软件程序的时候,跟踪和监控日志是一种记录过程的好方法. 简介: 在运行软件程序的时候,跟踪和监控日志是一种记录过程的好方法.尤其在应用程序出错的时候,日志是我们最需要的文件.不管是在web,wi ...

  8. jdbc连接oracle时使用的字符串格式

    两种方式: SID的方式: jdbc:oracle:thin:@[HOST][:PORT]:SID SERVICE_NAME的方式: jdbc:oracle:thin:@//[HOST][:PORT] ...

  9. 学习笔记<3>View接触

    一.View基本概念 1.界面上显示所有的控件都是用对象表示的,即有类,这些类都是View的子类. 2.View的种类 二.在Activity当中获取代表View的对象 1.根据ID可以用方法获取到对 ...

  10. jQuery属性--html([val|fn])、text([val|fn])和val([val|fn|arr])

    html([val|fn]) 概述 取得第一个匹配元素的html内容,这个函数不能用于XML文档.但可以用于XHTML文档. 在一个 HTML 文档中, 我们可以使用 .html() 方法来获取任意一 ...