线段树求调

P1047 [NOIP2005 普及组] 校门外的树

Endline @ 2022-07-26 10:01:14

#include<bits/stdc++.h>
#define MAXN 10002
#define mod 1000000007ll
#define ls(x) x<<1
#define rs(x) x<<1|1
using namespace std;
namespace FastIO
{
    char buf[1<<23],*p1,*p2;
    #define reg register
    #ifdef ONLINE_JUDGE
    #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1==p2))?EOF:*p1++
    #else
    #define gc() getchar()
    #endif
    inline int read()
    {
        reg int f=1,w=0;reg char ch=gc();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
        while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=gc();
        return f*w;
    }
}
using FastIO::read;
int l,m,ans;
int a[MAXN];
int tr[MAXN<<2];
inline void push_up(int p)
{
    tr[p]=tr[ls(p)]+tr[rs(p)];
    return;
}
inline void build(int l,int r,int p)
{
    if(l==r)
    {
        tr[p]=1;
        return;
    }
    int mid=(l+r)>>1;
    build(l,mid,ls(p));build(mid+1,r,rs(p));
    push_up(p);
    return;
}
inline void change(int l,int r,int s,int t,int p)
{
    if(s>=l&&t<=r)
    {
        tr[p]=0;
        return;
    }
    int mid=(s+t)>>1;
    if(mid>=l)change(l,r,s,mid,ls(p));
    if(mid<r)change(l,r,mid+1,t,rs(p));
    push_up(p);
    return;
}
int main()
{
    l=read(),m=read();
    build(0,l,1);
    for(int i=1;i<=m;i++)
    {
        int u=read(),v=read();
        change(u,v,0,l,1);
    }
    printf("%d\n",tr[1]);
    // for(int i=1;i<=m;i++)
    // {
    //     int u=read(),v=read();
    //     for(int j=u;j<=v;j++)
    //         a[j]=1;
    // }
    // ans=l+1;
    // for(int i=0;i<=l;i++)
    //     ans-=a[i];
    // printf("%d\n",ans);
    return 0;
}

by qinyubo @ 2022-07-26 10:10:13

@Endline 你在钓鱼吗?


by xie_lzh @ 2022-07-26 10:26:41

钓鱼佬(


by Tzj123_ORZ @ 2022-08-01 15:51:14


|