Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor

来源:互联网 发布:qq表情生成软件 编辑:程序博客网 时间:2024/05/19 13:06


Codeforces Round #435 (Div. 2) C.  :Mahmoud and Ehab and the xor


time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.

Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set ofn distinct non-negative integers such the bitwise-xor sum of the integers in it is exactlyx. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than106.

Input

The only line contains two integers n andx (1 ≤ n ≤ 105,0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively.

Output

If there is no such set, print "NO" (without quotes).

Otherwise, on the first line print "YES" (without quotes) and on the second line printn distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.

Examples
Input
5 5
Output
YES1 2 4 5 7
Input
3 6
Output
YES1 2 5
Note

You can read more about the bitwise-xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR

For the first sample .

For the second sample .





   题意:  找出n 个不同元素的集合,其异或值为 x;

  

   思路: 考虑异或的特性,暴力肯定不好写,那么我们可以想到

  (0^1^2^...^n-2)^(0^1^2^...^n-2)^x = x ;

  又 可能出现重复的数字,题中说 x <  1e5  ,那么如果出现了重复的数字 ,可以给两项同时异或一个大于 1e 5  的数。

注意可能是 a(n-1)==a(n-2); 所以要判断一下。

 特判一下  n==1 ||n==2&&x==0  的情况。



 

#include <bits/stdc++.h>using namespace std;int n, x;int a[100005];int main(){    cin>>n>>x;    if (n == 1)    {        cout<<"YES"<<endl<<x<<endl;        return 0;    }    if (n == 2)        if (x == 0)        {             cout <<"NO"<< endl;return 0;        }    cout <<"YES"<< endl;    a[n-1]=x;    for(int i=0;i<n-1;i++)    {        a[i]=i;        a[n-1]^=i;    }    if(a[n-1]<n-1)    {        if(a[n-1]!=a[n-2])            a[n-2]^= (1<<17);        else            a[n-3]^= (1<<17);        a[n-1]^= (1<<17);    }    for(int i=0;i<n;i++)        printf("%d%c",a[i],i==n-1?'\n':' ');    return 0;}


阅读全文
0 0