P1840 [Color the Axis_NOI Guide 2011 increase (05)]

It provides a relatively simple wording tree line

Do not build, ask also down

A whole tree to maintain the number of white dots, each change to find the precise range and a whole range are white spots

If we change the time interval found to be accessed has been fully covered, you can return directly, no need to change

Answer, then the output,  TR [. 1]  is the total number of white point range, so the answer is  n-tr [1]

#include<iostream>
#include<cstdio>
#define lson k<<1,l,mid
#define rson k<<1|1,mid+1,r
#define ls k<<1
#define rs k<<1|1
#define mid ((l+r)>>1)
using namespace std;
const int maxn=200005;
int n,m;
int tr[maxn<<2];
inline void update(int k){
    tr[k]=tr[ls]+tr[rs];
}
void change(int k,int l,int r,int x,int y){
    if(tr[k]==r-l+1)return ;
    if(l==x&&y==r){
        tr[k]=r-l+1;
        return ;
    }
    if(y<=mid)change(lson,x,y);
    else if(x>mid)change(rson,x,y);
    else change(lson,x,mid),change(rson,mid+1,y);
    update(k);
}
int main(){
    scanf("%d%d",&n,&m);
    int x,y;
    while(m--){
        scanf("%d%d",&x,&y);
        change(1,1,n,x,y);
        printf("%d\n",n-tr[1]);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/sanjinliushi/p/11568901.html
Recommended