为什么在洛谷上AC,但是其他OI全RE?

P1908 逆序对

NirvanaCeleste @ 2024-07-11 07:03:15

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500100;
long long tree[MAXN],ranks[MAXN];
long long ans,n;
struct point {
    long long num,val;
} a[MAXN];
bool cmp(point q,point w) {
    if(q.val == w.val) return q.num < w.num;
    return q.val < w.val;
}
void add(int p,long d) {
    for(; p<=n; p += p & (-p)) tree[p] += d;
}
long long sum(int p) {
    long long pll = 0;
    for(; p; p -= p & (-p)) pll += tree[p];
    return pll;
}
int main() {
    scanf("%lld\n",&n);
    for(int i=1; i<=n; i++){
        scanf("%lld\n",&a[i].val);
        a[i].num = i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1; i<=n; i++) ranks[a[i].num] = i;
    for(int i=n; i>=1; i--) {
        ans += sum(ranks[i] - 1);
        add(ranks[i],1);
    }
    printf("%lld\n",ans);
    return 0;
}

by Kete @ 2024-07-11 11:52:42

不好意思 刚才发错了


by NirvanaCeleste @ 2024-07-12 10:26:43

@shengzhe0227 @FiraCode @Lyw_Cyq_01 @Morax_Rock @qiuribomu

明白了

B. 【模板】逆序对统计

传统题 文件IO:deseq 1000ms 256MiB

没用freopn...


by qiuribomu @ 2024-07-12 10:31:20

@NirvanaCeleste

是freopen


上一页 |