/ 21班 /

记录详情

Accepted


  
[Hydro](https://hydro.ac)提供评测服务
# 状态 耗时 内存占用
#1 Accepted 5ms 460.0 KiB
#2 Accepted 4ms 540.0 KiB
#3 Accepted 4ms 688.0 KiB
#4 Accepted 4ms 540.0 KiB
#5 Accepted 4ms 540.0 KiB
#6 Accepted 19ms 796.0 KiB
#7 Accepted 18ms 796.0 KiB
#8 Accepted 19ms 796.0 KiB
#9 Accepted 19ms 796.0 KiB
#10 Accepted 18ms 796.0 KiB

代码

#include<bits/stdc++.h>

#ifdef WIN32
#define outl "%I64d"
#else
#define outl "%lld"
#endif

using namespace std;

typedef long long LL;
const int MAXN = 1000005;
int n, a[MAXN], c[MAXN];
LL ans;

int low_bit(int x){
    return x & -x;
}

void insert(int x){
    while(x < 1000000){
        c[x]++;
        x += low_bit(x);
    }
}

LL query(int x){
    LL res = 0;
    while(x){
        res += c[x];
        x -= low_bit(x);
    }
    return res;
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for(int i = n; i >= 1; i--){
        ans += query(a[i]);
        insert(a[i]+1);
    }
    printf(outl, ans);
    return 0;
}

信息

递交者
类型
递交
题目
P1026 逆序对
题目数据
下载
语言
C++
递交时间
2023-11-12 19:56:59
评测时间
2023-12-08 19:30:13
评测机
分数
100
总耗时
119ms
峰值内存
796.0 KiB