后面一半WA求条

P1908 逆序对

yupeishan2012 @ 2024-10-11 19:28:47


#include <bits/stdc++.h>
using namespace std;

long long n;
long long a[100005],b[100005],c[100005];
long long ans;

inline void read(register long long &a){
    a = 0;
    char c;
    while((c = getchar()) < 48);
    do a = (a << 3) + (a << 1) + (c ^ 48);
    while((c  = getchar()) > 47);
}

void write(register long long v){
    if(v < 10) putchar(v|48);
    else write(v / 10),putchar(v % 10 | 48);
}

long long cmp(long long j,long long k){
    if(a[j] == a[k]) return j > k;
    return a[j] > a[k];
}

long long lowbit(int k){
    return k & -k;
}

void x(long long k){
    while(k <= n){
        b[k] ++;
        k += lowbit(k);
    }
    return ;
}

long long sum;

long long y(int k){
    sum = 0;
    while(k >= 1){
        sum += b[k];
        k -= lowbit(k);
    }
    return sum;
}

int main(){
    read(n);
    for(long long i = 1; i <= n; i++){
        read(a[i]);
        c[i] = i;
    }
    sort(c + 1,c + 1 + n,cmp);
    for(long long i = 1; i <= n; i++){
        x(c[i]);
        ans += y(c[i] - 1);
    }
    write(ans);
    return 0;
}

by yupeishan2012 @ 2024-10-11 19:42:11

啊 我不是这么弄的吗


by YAOhc2012 @ 2024-10-11 19:43:20

@yupeishan2012 你觉得自己怎么弄的


by yupeishan2012 @ 2024-10-11 19:43:25

我就是想问问怎么改


by YAOhc2012 @ 2024-10-11 19:44:09

就是我之前发的用结构体


by ggpw_XNW @ 2024-10-11 19:45:53

@yupeishan2012 有没有一种可能你要把三个数据变成一个结构体


by yupeishan2012 @ 2024-10-11 19:47:22

@User1025109 @YAOhc2012 好的 那我改成结构体试试吧


by ggpw_XNW @ 2024-10-11 19:53:26

@yupeishan2012 你还没改完啊


by yupeishan2012 @ 2024-10-11 19:55:27

@User1025109 还有啥


by YAOhc2012 @ 2024-10-11 19:57:40

@yupeishan2012 交一发


by ggpw_XNW @ 2024-10-11 19:57:49

@yupeishan2012 可能要开ULL


上一页 | 下一页