EZOJ # 361 Geography

analysis

Respectively, and r is the number of maintenance l

Then the inquiry interval [L, R]

After l tree array R less than or equal to the number of minus L r is less than the array tree

Code

#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;
}

Guess you like

Origin www.cnblogs.com/yzxverygood/p/11520411.html