EZOJ #361地理

分析

就是分别维护l和r的个数

然后对于询问区间[L,R]

之后l树状数组中小于等于R的个数减掉r树状数组中小于L的即可

代码

#include<bits/stdc++.h>
using namespace std;
int n;
struct BIT {
    int d[100100];
    inline int lb(int x){return x&(-x);}
    inline void add(int x){while(x<=n)d[x]++,x+=lb(x);}
    inline int que(int x){int res=0;while(x)res+=d[x],x-=lb(x);return res;}
};
BIT a,b;
int main(){
    int i,j,k,x,y;
    cin>>n;
    for(i=1;i<=n;i++){
      scanf("%d",&k);
      if(k==1)scanf("%d%d",&x,&y),a.add(x),b.add(y);
        else scanf("%d%d",&x,&y),printf("%d\n",a.que(y)-b.que(x-1));
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/yzxverygood/p/11520411.html