菜的人就要写简单题

为了练习手速来写这样一道 珂朵莉树 线段树简单题

没啥可说的,注意修改操作中要判一下 val=0

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=200007;
  4. int val[maxn*4],lazy[maxn*4];
  5. #define lfc (x<<1)
  6. #define rgc ((x<<1)|1)
  7. #define mid ((l+r)>>1)
  8. int n,T;
  9. void pushup(int x){
  10. val[x]=val[lfc]+val[rgc];
  11. }
  12. void build(int x,int l,int r){
  13. if(l==r){
  14. val[x]=1;return;
  15. }
  16. build(lfc,l,mid);build(rgc,mid+1,r);
  17. pushup(x);
  18. }
  19. int L,R;
  20. void change(int x,int l,int r){
  21. if(r<L||R<l) return;
  22. if(L<=l&&r<=R){
  23. val[x]=0;return;
  24. }
  25. if(!val[x]) return;
  26. change(lfc,l,mid);change(rgc,mid+1,r);
  27. pushup(x);
  28. }
  29. int query(void){
  30. return val[1];
  31. }
  32. int main(){
  33. scanf("%d%d",&n,&T);
  34. build(1,1,n);
  35. while(T--){
  36. int l,r;
  37. scanf("%d%d",&l,&r);
  38. L=l,R=r;change(1,1,n);
  39. printf("%d\n",query());
  40. }
  41. return 0;
  42. }

LG1840 Color the Axis 线段树的更多相关文章

  1. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  2. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  3. hdu 6183 Color it (线段树 动态开点)

    Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...

  4. hdu 1556 Color the ball (线段树+代码详解)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. 2018.07.08 hdu6183 Color it(线段树)

    Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Proble ...

  6. hdu 1556 Color the ball(线段树区间维护+单点求值)

    传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  7. HDU - 6183:Color it (线段树&动态开点||CDQ分治)

    Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...

  8. Count Color POJ - 2777 线段树

    Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds ...

  9. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

随机推荐

  1. C lang:Definition function

    Ax_note in parameter for show_n_char() is formal parameter Aa_Definition function #include <stdio ...

  2. CODING 受邀参与 DevOps 标准体系之系统和工具&技术运营标准技术专家研讨会

    2019 年 5 月 24-25 日,国内领先的一站式 DevOps 解决方案供应商 CODING 作为腾讯云的深度合作伙伴,受邀参加在成都举行的由 TC608 云计算标准和开源推进委员会主办,中国信 ...

  3. CentOS7 安装Python3.6.8

    CentOS7 安装Python3.6.8 1. 安装依赖环境 yum -y groupinstall "Development tools" yum -y install zli ...

  4. pycharm报错:Process finished with exit code -1073741819 (0xC0000005)解决办法

    这个是几个月前的问题了,有小伙伴在CSDN问我咋解决的,那我今天在这边把这个问题解决办法分享下吧,免得大家把很多时间都浪费在安装排坑上面,有些坑虽然解决了还真不知道啥原因. 我的pycharm一直用的 ...

  5. R-5 相关分析-卡方分析

    本节内容: 1:相关分析 2:卡方分析 一.相关分析 相关系数: 皮尔逊相关系数:一般用来计算两个连续型变量的相关系数. 肯德尔相关系数:一个连续一个分类(最好是定序变量) 斯皮尔曼相关系数:2个变量 ...

  6. 【oracle】ORA-06550 字符串长度限制在范围

    number(2)输入了100 就会导致异常

  7. [译]Vulkan教程(30)深度缓存

    [译]Vulkan教程(30)深度缓存 Depth buffering 深度缓存 Introduction 入门 The geometry we've worked with so far is pr ...

  8. IT兄弟连 HTML5教程 HTML5表单 新增的表单属性3

    9  novalidate novalidate是属性规定在提交表单时不应该验证form和input域.novalidate属性适用于的<input>类型有:text.search.url ...

  9. UNIX系统编程知识点总结——思维导图

    根据考纲整理了一下本学期系统编程课的知识点,并且做成了思维导图便于理解和记忆 主要都是一些比较入门的知识点,UNIX博大精深,每一个知识点其实都能深挖 因为博客园不可能直接出思维导图,本文的主要内容都 ...

  10. SpringBoot控制台版图书借阅程序

    // 实验存档... 效果图: 完整程序:https://pan.baidu.com/s/1-d1J90dkEtM0WKkABu0K0Q 提取码:hcnm DAO层代码由MyBatis Generat ...