码迷,mamicode.com
首页 > 其他好文 > 详细

PAT T1010 Lehmer Code

时间:2020-02-13 13:00:41      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:ons   c++   ace   owb   col   space   std   mes   printf   

跟1009几乎是同一道题~

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+14;
int a[maxn];
int c[maxn*8];
int r[maxn];
int lowbit (int x) {
    return x&-x;
}
int main () {
    int N;
    scanf ("%d",&N);
    for (int i=0;i<N;i++) {
        scanf ("%d",&a[i]);
        a[i]+=10010;
    }
    for (int i=N-1;i>=0;i--) {
        for (int j=a[i]-1;j>0;j-=lowbit(j)) 
        r[i]+=c[j];
        for (int j=a[i];j<maxn;j+=lowbit(j))
        c[j]++;
    } 
    for (int i=0;i<N;i++) {
        if (i!=0) printf (" ");
        printf ("%d",r[i]);
    }
    return 0;
}

 

PAT T1010 Lehmer Code

标签:ons   c++   ace   owb   col   space   std   mes   printf   

原文地址:https://www.cnblogs.com/zhanglichen/p/12302852.html

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