兔子的逆序对(树状数组逆序对)
标签:href oid acm void win tps typedef https clu
https://ac.nowcoder.com/acm/problem/20861
#include#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(;ilow(i))
cnt+=a[i];
return cnt;
}
int main(){
scanf("%d",&n);
ll ans=0;
for(int i=1;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;
}
兔子的逆序对(树状数组逆序对)
标签:href oid acm void win tps typedef https clu
原文地址:https://www.cnblogs.com/xcfxcf/p/12979441.html
评论