CH4201楼兰图腾

不知道再哪里炸了longlong,懒得想了,全开就好了

#include <bits/stdc++.h>
using namespace std;
long long a[200100], c[200100], c1[200100], c2[200100], n;
long long ans1 = 0, ans2 = 0;
long long getsum(long long p) {
    long long ans = 0;
    for (; p; p -= p & -p) {
        ans += c[p];
    }
    return ans;
}
void insert1(long long id, long long p) {
    for (; id <= n + 1; id += id & -id) c1[id] += p;
}
void insert2(long long id, long long p) {
    for (; id <= n + 1; id += id & -id) c2[id] += p;
}
void insert(long long p) {
    for (long long i = p; i <= n + 1; i += i & -i) c[i] += 1;
}
long long getsum1(long long p) {
    long long ans = 0;
    for (; p; p -= p & -p) ans += c1[p];
    return ans;
}
long long getsum2(long long p) {
    long long ans = 0;
    for (; p; p -= p & -p) ans += c2[p];
    return ans;
}
int main() {
    // freopen("xf.in","r",stdin);
    // freopen("xf.out","w",stdout);
    scanf("%d", &n);
    for (long long i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        ans1 += getsum1(a[i] - 1);
        ans2 += getsum2(n + 1) - getsum2(a[i]);
        insert(a[i]);
        insert1(a[i], getsum(n + 1) - getsum(a[i]));
        insert2(a[i], getsum(a[i] - 1));
    }
    printf("%lld %lld\n", ans1, ans2);
    return 0;
}

 

posted @ 2020-09-03 16:34  mybing  阅读(119)  评论(0编辑  收藏  举报