兔子的逆序对(树状数组逆序对)
https://ac.nowcoder.com/acm/problem/20861
#include<bits/stdc++.h> #define low(x) (x&(-x)) using namespace std; const int N=1e5+5; typedef long long ll; int a[N]; int n; void add(int i,int d){ for(;i>0;i-=low(i)) a[i]+=d; } int ask(int i){ int cnt=0; for(;i<=n;i+=low(i)) cnt+=a[i]; return cnt; } int main(){ scanf("%d",&n); ll ans=0; for(int i=1;i<=n;i++){ int num; scanf("%d",&num); ans+=ask(num); add(num,1); } ans%=2; int m; scanf("%d",&m); while(m--){ int l,r; scanf("%d%d",&l,&r); int tmp=((r-l+1)/2)%2; if(tmp) ans=(ans+1)%2; if(ans) printf("dislike\n"); else printf("like\n"); } return 0; }