标签:push pac c++ change axis include 练习 uil ||
菜的人就要写简单题
为了练习手速来写这样一道 珂朵莉树 线段树简单题
没啥可说的,注意修改操作中要判一下 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;
}
标签:push pac c++ change axis include 练习 uil ||
原文地址:https://www.cnblogs.com/liubainian/p/12026567.html