CF1157E.Minimum Array

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two arrays aa and bb, both of length nn. All elements of both arrays are from 00 to n−1n-1.

You can reorder elements of the array bb (if you want, you may leave the order of elements as it is). After that, let array cc be the array of length nn, the ii-th element of this array is ci=(ai+bi)%nc_i = (a_i + b_i) \% n, where x%yx \% y is xx modulo yy.

Your task is to reorder elements of the array bb to obtain the lexicographically minimum possible array cc.

Array xx of length nn is lexicographically less than array yy of length nn, if there exists such ii (1≤i≤n1 \le i \le n), that xi<yix_i \lt y_i, and for any jj (1≤j<i1 \le j \lt i) xj=yjx_j = y_j.

给你两个长度均为 nn 的数组 aa 和 bb,这两个数组的所有元素均在 00 到 n−1n-1 之间。

你可以对数组 bb 的元素进行重排(当然也可以保持原顺序不变)。重排后,定义长度为 nn 的数组 cc,其第 ii 个元素为 ci=(ai+bi)%nc_i = (a_i + b_i) \% n,其中 x%yx \% y 表示 xx 对 yy 取模。

你的任务是重排数组 bb,使得所得数组 cc 的字典序尽可能小。

长度为 nn 的数组 xx 字典序小于长度为 nn 的数组 yy,当且仅当存在某个下标 ii(1≤i≤n1 \le i \le n),使得 xi<yix_i \lt y_i,且对任意 jj(1≤j<i1 \le j \lt i)均有 xj=yjx_j = y_j。

输入格式

The first line of the input contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of elements in aa, bb and cc.

The second line of the input contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai<n0 \le a_i \lt n), where aia_i is the ii-th element of aa.

The third line of the input contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (0≤bi<n0 \le b_i \lt n), where bib_i is the ii-th element of bb.

输入的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示数组 aa、bb 和 cc 的元素个数。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai<n0 \le a_i \lt n),其中 aia_i 是数组 aa 的第 ii 个元素。

输入的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(0≤bi<n0 \le b_i \lt n),其中 bib_i 是数组 bb 的第 ii 个元素。

输出格式

Print the lexicographically minimum possible array cc. Recall that your task is to reorder elements of the array bb and obtain the lexicographically minimum possible array cc, where the ii-th element of cc is ci=(ai+bi)%nc_i = (a_i + b_i) \% n.

输出字典序最小的可能数组 cc。注意,你的任务是对数组 bb 的元素重新排序,从而得到字典序最小的可能数组 cc,其中 cc 的第 ii 个元素为 ci=(ai+bi)%nc_i = (a_i + b_i) \% n。

输入输出样例

  • 输入#1

    4
    0 1 2 1
    3 2 1 1

    输出#1

    1 0 0 2
  • 输入#2

    7
    2 5 1 5 3 4 3
    2 4 3 5 6 5 1

    输出#2

    0 0 0 1 0 2 4

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

首页