CF501D.Misha and Permutations Summation

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's define the sum of two permutations p and q of numbers 0, 1, ..., (n - 1) as permutation , where Perm(x) is the x-th lexicographically permutation of numbers 0, 1, ..., (n - 1) (counting from zero), and Ord(p) is the number of permutation p in the lexicographical order.

For example, Perm(0) = (0, 1, ..., n - 2, n - 1), Perm(n! - 1) = (n - 1, n - 2, ..., 1, 0)

Misha has two permutations, p and q. Your task is to find their sum.

Permutation a = (_a_0, _a_1, ..., a__n - 1) is called to be lexicographically smaller than permutation b = (_b_0, _b_1, ..., b__n - 1), if for some k following conditions hold: _a_0 = _b_0, _a_1 = _b_1, ..., a__k - 1 = b__k - 1, a__k < b__k.

我们定义两个排列 pp 和 qq(均为 0,1,…,n−10,1,\ldots,n-1 的排列)的和为排列
,
其中 Perm(x)\mathrm{Perm}(x) 表示 0,1,…,n−10,1,\ldots,n-1 的所有排列中字典序第 xx 小的排列(从 00 开始计数),而 Ord(p)\mathrm{Ord}(p) 表示排列 pp 在字典序中的序号(即其排名,从 00 开始)。

例如,Perm(0)=(0,1,…,n−2,n−1)\mathrm{Perm}(0) = (0,1,\ldots,n-2,n-1),Perm(n!−1)=(n−1,n−2,…,1,0)\mathrm{Perm}(n!-1) = (n-1,n-2,\ldots,1,0)。

米沙有两个排列 pp 和 qq。你的任务是求出它们的和。

排列 a=(a0,a1,…,an−1)a = (a_0,a_1,\ldots,a_{n-1}) 被称为字典序小于排列 b=(b0,b1,…,bn−1)b = (b_0,b_1,\ldots,b_{n-1}),当且仅当存在某个 kk,使得以下条件成立:
a0=b0, a1=b1, …, ak−1=bk−1, ak<bka_0 = b_0,\ a_1 = b_1,\ \ldots,\ a_{k-1} = b_{k-1},\ a_k < b_k。

输入格式

The first line contains an integer n (1 ≤ n ≤ 200 000).

The second line contains n distinct integers from 0 to n - 1, separated by a space, forming permutation p.

The third line contains n distinct integers from 0 to n - 1, separated by spaces, forming permutation q.

第一行包含一个整数 nn(1≤n≤200 0001 \leq n \leq 200\,000)。

第二行包含 nn 个互不相同的、取值范围为 00 到 n−1n-1 的整数,以空格分隔,构成排列 pp。

第三行包含 nn 个互不相同的、取值范围为 00 到 n−1n-1 的整数,以空格分隔,构成排列 qq。

输出格式

Print n distinct integers from 0 to n - 1, forming the sum of the given permutations. Separate the numbers by spaces.

输出 $ n $ 个互不相同的整数,取值范围为 $ 0 $ 到 $ n-1 $,使得它们的和等于给定排列的和。数字之间用空格分隔。

输入输出样例

  • 输入#1

    2
    0 1
    0 1

    输出#1

    0 1
  • 输入#2

    2
    0 1
    1 0

    输出#2

    1 0
  • 输入#3

    3
    1 2 0
    2 1 0

    输出#3

    1 0 2

说明/提示

Permutations of numbers from 0 to 1 in the lexicographical order: (0, 1), (1, 0).

In the first sample Ord(p) = 0 and Ord(q) = 0, so the answer is .

In the second sample Ord(p) = 0 and Ord(q) = 1, so the answer is .

Permutations of numbers from 0 to 2 in the lexicographical order: (0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0).

In the third sample Ord(p) = 3 and Ord(q) = 5, so the answer is .

数字 0 到 1 的所有排列按字典序排列为:(0, 1), (1, 0)。

在第一个样例中,Ord(p) = 0 且 Ord(q) = 0,因此答案为 。

在第二个样例中,Ord(p) = 0 且 Ord(q) = 1,因此答案为 。

数字 0 到 2 的所有排列按字典序排列为:(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)。

在第三个样例中,Ord(p) = 3 且 Ord(q) = 5,因此答案为 。

输入解题思路,AI测评打分。不知道怎么写?

首页