LG1840 Color the Axis 线段树
菜的人就要写简单题
为了练习手速来写这样一道 珂朵莉树 线段树简单题
没啥可说的,注意修改操作中要判一下 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 线段树的更多相关文章
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hdu 6183 Color it (线段树 动态开点)
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...
- hdu 1556 Color the ball (线段树+代码详解)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 2018.07.08 hdu6183 Color it(线段树)
Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Proble ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- HDU - 6183:Color it (线段树&动态开点||CDQ分治)
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B ...
- Count Color POJ - 2777 线段树
Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds ...
- ZOJ 2301 Color the Ball 线段树(区间更新+离散化)
Color the Ball Time Limit: 2 Seconds Memory Limit: 65536 KB There are infinite balls in a line ...
随机推荐
- 挑选(pick)
挑选(pick) 1s/128MB [题目背景] NOIP2017 马上就要到了,丁爷爷想要从他的小朋友里挑选出一些厉害的来参加NOIP. [题目描述] 丁爷爷共有 n 个小朋友,按编号 1 . . ...
- Android框架式编程之Retrofit
一.Retrofit 简介 Retrofit 官网地址: https://github.com/square/retrofit Retrofit(即Retrofit,目前最新版本为2.6.0版本),是 ...
- 【Objective-C】探索Category底层的实质
无论一个类设计的多么完美,在未来的需求演进中,都有可能会碰到一些无法预测的情况.那怎么扩展已有的类呢?一般而言,继承和组合是不错的选择.但是在Objective-C 2.0中,又提供了category ...
- 小白到大神,你需要了解的 sqlite 最佳实践
本文微信公众号「AndroidTraveler」首发. 背景 本文是对一篇英文文档的翻译,原文请见文末链接. 并发数据库访问 假设你实现了自己的 SQLiteOpenHelper. public cl ...
- Android WebView与H5联调技巧
版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/78 背景: 突然想写一篇关于Android WebView ...
- SpringCloud之Zuul:服务网关
Zuul在Web项目中的使用见上文<SpringBoot中使用Zuul>,下面例子为Zuul在Spring Cloud的使用. 开发工具:IntelliJ IDEA 2019.2.3 一. ...
- stream根据条件过滤List<Object>
List<String> filterUser= new ArrayList<>(); filterUser.add("张三"); List<User ...
- 史上最全Oracle数据泵常用命令
本文转自https://blog.csdn.net/Enmotech/article/details/102848825 墨墨导读:expdp和impdp是oracle数据库之间移动数据的工具,本文简 ...
- 《HTTPS权威指南》读书笔记——PKI
互联网公钥基础设施 基于可信的第三方机构(CA,certification authority)实现不同成员在不见面的情况下进行安全通信 订阅人 需要证书来提供安全服务的团体 登记机构(RA) 完成证 ...
- win10 安装cuda和cudnn
首先通过nvidia-smi 查看自己的显卡驱动对应的cuda版本. 参考:https://blog.csdn.net/qq_40212975/article/details/89963016 再去官 ...