2 条题解

  • 0
    @ 2023-4-26 20:21:47
    #include<bits/stdc++.h>
    using namespace std;
    const int Maxn=50010;
    int CL[Maxn],CR[Maxn];
    int n,m,N=Maxn;
    int lowbit(int x){
        return x&(-x);
    }
    int Sum(int C[], int x){
        int res=0;
        for(; x; x-=lowbit(x)){
            res+=C[x];
        }
      return res;
    }
    void Update(int c[], int x ,int d){
        for(; x<=n;x+=lowbit(x)){
            c[x]+=d;
        }
    }
    int main()
    {
        cin>>n>>m;
        int opt,x,y;
        while(m--){
            cin>>opt>>x>>y;
            if(opt==1){
                Update(CL,x,1);
                Update(CR,y,1);
            }
            else{
                cout<<Sum(CL,y)-Sum(CR,x-1)<<endl;
            }
            
        }
    }
    

    很有精神!

    「一本通 4.1 例 3」校门外的树

    信息

    ID
    594
    时间
    1000ms
    内存
    512MiB
    难度
    5
    标签
    递交数
    31
    已通过
    15
    上传者