PAT TOP 1010. Lehmer Code (35)

问题描述:

1010. Lehmer Code (35)

时间限制
300 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
LIU, Yaoting

According to Wikipedia: "In mathematics and in particular in combinatorics, the Lehmer code is a particular way to encode each possible permutation of a sequence of n numbers." To be more specific, for a given permutation of items {A1, A2, ..., An}, Lehmer code is a sequence of numbers {L1, L2, ..., Ln} such that Li is the total number of items from Ai to An which are less than Ai. For example, given {24, 35, 12, 1, 56, 23}, the second Lehmer code L2 is 3 since from 35 to 23 there are three items, {12, 1, 23}, less than the second item, 35.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (<= 105). Then N distinct numbers are given in the next line.

Output Specification:

For each test case, output in a line the corresponding Lehmer code. The numbers must be separated by exactly one space, and there must be no extra space at the beginning or the end of the line.

Sample Input:
6
24 35 12 1 56 23
Sample Output:
3 3 1 0 1 0

又是一道来给我pb_ds tree送经验的题。。。。

不多说,直接上AC代码:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
int main()
{
//	freopen("data.txt","r",stdin);
	int n,x,c1,c2;
	tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> tr;
	scanf("%d",&n);
	vector<int> v(n);
	for(int i=0;i<n;i++)
	scanf("%d",&v[i]);
	for(int i=n-1;i>-1;i--)
	{
		tr.insert(v[i]);
		v[i]=tr.order_of_key(v[i]);
	}
	printf("%d",v[0]);
	for(int i=1;i<n;++i)
	printf(" %d",v[i]);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值