C. Splitting the Uniqueness
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Polar bears like unique arrays — that is, arrays without repeated elements.

You have got a unique array s with length n containing non-negative integers. Since you are good friends with Alice and Bob, you decide to split the array in two. Precisely, you need to construct two arrays a and b that are also of length n, with the following conditions for all i(1 ≤ i ≤ n):

  • ai, bi are non-negative integers;
  • si = ai + bi .

Ideally, a and b should also be unique arrays. However, life in the Arctic is hard and this is not always possible. Fortunately, Alice and Bob are still happy if their arrays are almost unique. We define an array of length n to be almost unique, if and only if it can be turned into a unique array by removing no more than  entries.

For example, the array [1, 2, 1, 3, 2] is almost unique because after removing the first two entries, it becomes [1, 3, 2]. The array [1, 2, 1, 3, 1, 2] is not almost unique because we need to remove at least 3 entries to turn it into a unique array.

So, your task is to split the given unique array s into two almost unique arrays a and b.

Input

The first line of the input contains integer n (1 ≤ n ≤ 105).

The second line contains n distinct integers s1, s2, ... sn (0 ≤ si ≤ 109).

Output

If it is possible to make Alice and Bob happy (if you can split the given array), print "YES" (without quotes) in the first line. In the second line, print the array a. In the third line, print the array b. There may be more than one solution. Any of them will be accepted.

If it is impossible to split s into almost unique arrays a and b, print "NO" (without quotes) in the first line.

Examples
input
6
12 5 8 3 11 9
output
YES
6 2 6 0 2 4
6 3 2 3 9 5
Note

In the sample, we can remove the first two entries from a and the second entry from b to make them both unique.

分析:

因为一个序列如果是近似不同的的序列,那么它有至少 ⌊ 2n / 3⌋的元素是不同的...所以我们把s序列分成三个部分,第一个部分保证a互不相同,第二个部分保证b互不相同,第三个部分保证ab都互不相同...如下图:

设x=n/3(上取整)

i∈[1,x] a=i-1

i∈[x+1,n-x] b=i-1

i∈[n-x+1,n] b=n-i+1

代码:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std;
//眉眼如初,岁月如故 const int maxn=100000+5; int n,x; struct M{
int a,b,s,id;
friend bool operator < (M a,M b){
return a.s<b.s;
}
}sxy[maxn]; inline bool cmp(M a,M b){
return a.id<b.id;
} signed main(void){
scanf("%d",&n);x=(n+2)/3;
for(int i=1;i<=n;i++)
scanf("%d",&sxy[i].s),sxy[i].id=i;
sort(sxy+1,sxy+n+1);
for(int i=1;i<=x;i++)
sxy[i].a=i-1,sxy[i].b=sxy[i].s-i+1;
for(int i=x+1;i<=n-x;i++)
sxy[i].b=i-1,sxy[i].a=sxy[i].s-i+1;
for(int i=n-x+1;i<=n;i++)
sxy[i].b=n-i,sxy[i].a=sxy[i].s-sxy[i].b;
sort(sxy+1,sxy+n+1,cmp);puts("YES");
for(int i=1;i<=n;i++)
printf("%d ",sxy[i].a);
puts("");
for(int i=1;i<=n;i++)
printf("%d ",sxy[i].b);
puts("");
return 0;
}//Cap ou pas cap. Pas cap.

  


By NeighThorn

Codeforces 297C. Splitting the Uniqueness的更多相关文章

  1. CodeForces 297C Splitting the Uniqueness (脑补构造题)

    题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指 ...

  2. Codeforces.297C.Splitting the Uniqueness(构造)

    题目链接 \(Description\) 给定一个长为n的序列A,求两个长为n的序列B,C,对任意的i满足B[i]+C[i]=A[i],且B,C序列分别至少有\(\lfloor\frac{2*n}{3 ...

  3. 【CodeForces 297C】Splitting the Uniqueness

    题意 序列s有n个数,每个数都是不同的,把它每个数分成两个数,组成两个序列a和b,使ab序列各自去掉个数后各自的其它数字都不同. 如果存在一个划分,就输出YES,并且输出两个序列,否则输出NO. 分析 ...

  4. Codeforces Round #180 (Div. 1 + Div. 2)

    A. Snow Footprints 如果只有L或者只有R,那么起点和终点都在边界上,否则在两者的边界. B. Sail 每次根据移动后的曼哈顿距离来判断是否移动. C. Parity Game 如果 ...

  5. Educational Codeforces Round 4 A. The Text Splitting 水题

    A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...

  6. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  7. Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)

    A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) C. Maximum splitting

    地址: 题目: C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input ...

  9. Codeforces Round #390 (Div. 2) A. Lesha and array splitting

    http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...

随机推荐

  1. Drop it-freecodecamp算法题目

    Drop it 1.要求 丢弃数组(arr)的元素,从左边开始,直到回调函数return true就停止. 第二个参数,func,是一个函数.用来测试数组的第一个元素,如果返回fasle,就从数组中抛 ...

  2. Dungeon Master POJ - 2251 (搜索)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48605   Accepted: 18339 ...

  3. 【数学 随机 技巧】cf364D. Ghd

    随机化选讲的例题 John Doe offered his sister Jane Doe find the gcd of some set of numbers a. Gcd is a positi ...

  4. php实现的三个常用加密解密功能函数示例

    目录 算法一: 算法二: 算法三(改进第一个加密之后的算法) 本文实例讲述了php实现的三个常用加密解密功能函数.分享给大家供大家参考,具体如下: 算法一: //加密函数 function lock_ ...

  5. python3下最全的wordcloud用法,附源代码及相关文件

    一.wordcloud是什么 词云,在一段文本中提取关键词进行扁平化的展示,更能吸引目标客户的眼球. 市面上有很多在线生成词云的工具,本文以Python中的第三方库wordcloud为例讲解如何自动生 ...

  6. mem_init()

    原本由bootmem管理的内存在mem_init函数中交由伙伴系统管理. 1.free_unused_memmap_node 相邻的membank间可能存在空洞,但在bootmem阶段这些空洞页也分配 ...

  7. Spark性能优化:开发调优篇

    1.前言 在大数据计算领域,Spark已经成为了越来越流行.越来越受欢迎的计算平台之一.Spark的功能涵盖了大数据领域的离线批处理.SQL类处理.流式/实时计算.机器学习.图计算等各种不同类型的计算 ...

  8. mysql--timestamp加减

    利用timestamp()对timestamp类型进行秒加减操作: 1.加10秒: 2.减10秒:

  9. js:随记

    typeof:没有大写,因为typeof是运算符 *1:是转数字 +string:是转数字,在Date对象上是getTime ""+:是转字符串 "":bool ...

  10. Linux下Oracle JDK替换Open JDK

    Oracle的产品需要Oracle JDK,但是Linux发行版附带的都是开源的Open JDK,这里给出的方法是在不删除原有Open JDK的情况下,安装Oracle JDK 环境 系统:CentO ...