码迷,mamicode.com
首页 > 编程语言 > 详细

兔子的逆序对(树状数组逆序对)

时间:2020-05-28 11:36:20      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:href   oid   acm   void   win   tps   typedef   https   clu   

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

 

兔子的逆序对(树状数组逆序对)

标签:href   oid   acm   void   win   tps   typedef   https   clu   

原文地址:https://www.cnblogs.com/xcfxcf/p/12979441.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!