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. 定位设备--llseek实现

    /** 如果llseek实现lseek和llseek系统调用,如果未定义llseek方法, 内核默认修改file结构体中的f_pos成员来实现定位,如果是操作一个 设备,则需提供自己的llseek方法 ...

  2. SAP 日志管理

    现在项目上自开发的dialog程序越来越多,有很多敏感数据需要像SAP标准的业务一样,能看到所有的修改日志,要想实现日志的功能,有以下几个办法: 办法一.建一个日志表,在原有表的基础上,加上日期和时间 ...

  3. HTML5页面元素中的文本最快速替换replace()方法

    $.ajax({ type:"get", url:spanUrl, dataType:'jsonp', jsonpCallback:'jsonp',//jsonp数据,需要数据库提 ...

  4. 20181225 基于TCP/IP和基于UDP/IP的套接字编程

    一.TCP/IP的套接字编程 服务器端代码: import  socket​server = socket.socket() # 默认是基于TCP# 基于TCP的对象serve=socket.sock ...

  5. Docker从零到实践过程中的坑

    欢迎指正: Centos7 下的ulimit在Docker中的坑 http://www.dockone.io/article/522 僵尸容器:Docker 中的孤儿进程 https://yq.ali ...

  6. 快速排序,对于相同元素的优化,c++

    #include<iostream>using namespace std; void middl(int &p,int &q,int &r)//找枢轴,然后把枢轴 ...

  7. 笔记-http-header

    笔记-http-header 1.      Requests部分 Host:请求的web服务器域名地址 User-Agent:HTTP客户端运行的浏览器类型的详细信息.通过该头部信息,web服务器可 ...

  8. jvm探秘之三:GC初步

    GC即垃圾收集器,虚拟机的必要组成部分. 不过这里说当然是,hotspot虚拟机(jvm的主要版本)的GC机制,前面说过了jvm的组成部分,那么想当然GC只需要负责方法区和堆就好了,虚拟机栈.本地方法 ...

  9. 4819: [Sdoi2017]新生舞会(分数规划)

    4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1031  Solved: 530[Submit][Statu ...

  10. phpstorm将本地代码传递到远程服务器

    由于对vim不太熟悉,效率比较低,作为过渡阶段,采用本地编写代码,然后上传到开发机上,进行调试 前提是服务器开启了ftp服务:http://www.cnblogs.com/redirect/p/693 ...