菜的人就要写简单题

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

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

#include<bits/stdc++.h>
using namespace std; const int maxn=200007; int val[maxn*4],lazy[maxn*4]; #define lfc (x<<1)
#define rgc ((x<<1)|1)
#define mid ((l+r)>>1) int n,T; void pushup(int x){
val[x]=val[lfc]+val[rgc];
} void build(int x,int l,int r){
if(l==r){
val[x]=1;return;
}
build(lfc,l,mid);build(rgc,mid+1,r);
pushup(x);
} int L,R; void change(int x,int l,int r){
if(r<L||R<l) return;
if(L<=l&&r<=R){
val[x]=0;return;
}
if(!val[x]) return;
change(lfc,l,mid);change(rgc,mid+1,r);
pushup(x);
} int query(void){
return val[1];
} int main(){
scanf("%d%d",&n,&T);
build(1,1,n);
while(T--){
int l,r;
scanf("%d%d",&l,&r);
L=l,R=r;change(1,1,n);
printf("%d\n",query());
}
return 0;
}

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. Python-xlwt库的基本使用

    安装xlwt库 pip install xlwt 基本使用 ①创建工作簿 wa = xlwt.Workbook() ②添加工作表 添加“class”工作表 b = wa.add_sheet('clas ...

  2. c# 保留2位小数 整数时无小数

    对数值保存两位小数,有时是整数时,不需要显示两位小数.例如值为:1.32 保留两位,结果是1.32,值为:2,结果有两种显示,2和2.00 /// <summary> /// 金额 /// ...

  3. 速查 objc中可变集合和不可变集合的遍历性能

    次数 : 5,000,000 NSMutableArray //0.131999/0.116085/0.112128 NSArray //0.116842/0.111675/0.108623 NSMu ...

  4. java web轻量级开发面试教程

    最近面试java后端开发的感受:如果就以平时项目经验来面试,通过估计很难——再论面试前的准备 在上周,我密集面试了若干位Java后端的候选人,工作经验在3到5年间.我的标准其实不复杂:第一能干活,第二 ...

  5. navicat for mysql 连接 mysql 出现Client does not support authentication protocol requested by server解决方案

    一 .桌面左下角windows图标--搜索框内输入cmd,结果如图所示,点击cmd.exe,或者使用快捷键Windows键(在键盘上有个Windows标志的按键)+R输入cmd后回车. 二. 在出来的 ...

  6. 【ES6学习笔记之】Object.assign()

    基本用法 Object.assign方法用于对象的合并,将源对象(source)的所有可枚举属性,复制到目标对象(target). const target = { a: 1 }; const sou ...

  7. nlohmann 最优秀的C++序列化工具库 详细入门教程

    本文首发于个人博客https://kezunlin.me/post/f3c3eb8/,欢迎阅读最新内容! tutorial to use nlohmann json for serializing d ...

  8. 2019年最新阿里Java工程师面试题

    一.单选题(共10题,每题5分) 1 关于设计模式遵循的原则,说法错误的是?   A.组合优于继承 B.针对实现编程 C.对扩展开放,对修改关闭 D.降低对象之间的耦合 参考答案:B 答案解析: 设计 ...

  9. 在ASP.NET中备份数据库以及还原(不成熟)

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  10. NIO零拷贝的深入分析

    深入分析通过Socket进行数据文件传递中的传统IO的弊端以及NIO的零拷贝实现原理,及用户空间和内核空间的切换方式 传统的IO流程 在这个过程中: 数据从磁盘拷贝进内核空间缓冲区 从内核空间缓冲区拷 ...