exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
bd82e7bd316a49a24700ed15bc8c433e
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue; import java.util.StringTokenizer; public class G { public static void main(String[]args) throws IOException { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); a:while(t-->0) { int n=sc.nextInt(); int[]ans=new int[n]; int i=0; if(n%2==1) {ans[0]=(n-1)%4==0?0:Integer.MAX_VALUE; i++; }else if(n%4!=0) { // int dig=26; int num=1<<dig; int num2=num/2; ans[0]=num;ans[1]=num2; ans[2]=1;ans[3]=num2|1; ans[4]=num|2;ans[5]=2; i=6; for(int cnt=3;i<n;i+=2,cnt++) { ans[i]=num|cnt; ans[i+1]=num2|cnt; } } for(int num=1;i<n;i+=2,num++) { ans[i]=num; ans[i+1]=num^Integer.MAX_VALUE; } // if(n%2==1) { // for(int i=1,num=1;i<n;i+=2,num++) { // ans[i]=num; // ans[i+1]=num^Integer.MAX_VALUE; // } // }else { // int i=0; // if(n%4==0) { // } // // } for(int x:ans)out.print(x+" "); out.println(); } out.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public boolean hasNext() {return st.hasMoreTokens();} public int nextInt() throws IOException {return Integer.parseInt(next());} public double nextDouble() throws IOException {return Double.parseDouble(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public boolean ready() throws IOException {return br.ready(); } } static class SegmentTree { int[][]arr,seg; int N; int UNCALC; public SegmentTree(int[][]arr) { // arr=new long[a.length][a[0].length]; // arr=a.clone(); this.arr=arr; N=arr.length-1; seg=new int[N<<1][arr[0].length]; build(1,1,N); } public void build(int node,int l,int r) { if(l==r) {seg[node]=arr[l];return;} int mid=(l+r)/2; build(node<<1,l,mid); build(node<<1|1,mid+1,r); seg[node]=merge(seg[node<<1],seg[node<<1|1]); } private int[] merge(int[] l, int []r) { int[]ans=new int[l.length]; if(l[0]==-1)return r; if(r[0]==-1)return l; // int sum1=0;for(int i=0;i<ans.length;i++)sum1+=l[i]; // if(sum1==0)return r; // sum1=0;for(int i=0;i<ans.length;i++)sum1+=r[i]; // if(sum1==0)return l; // ans[0]=l[0]; ans[1]=r[1]; //2 is pre, 3 is suff, 5 is total ans[4]=l[4]+r[4];//width ans[2]=l[2]; if(l[2]==l[4]&&l[1]<=r[0])ans[2]+=r[2]; ans[3]=r[3]; if(r[3]==r[4]&&l[1]<=r[0])ans[3]+=l[3]; ans[5]=l[5]+r[5]; if(l[1]<=r[0])ans[5]--; return ans; } public long query(int i,int j) { int[]a=query(1,1,N,i,j); return a[5]; } public int[] query(int node,int l,int r,int i,int j) {//quering on i and j if(l>j||r<i) { int[]ot=new int[arr[0].length]; ot[0]=-1; ot[1]=Integer.MAX_VALUE; return ot; } if(r<=j&&l>=i)return seg[node]; int mid=l+r>>1; int[] left=query(node<<1,l,mid,i,j); int[] right=query(node<<1|1,mid+1,r,i,j); return merge(left,right); } public void updatePoint(int idx,int val) { int node=idx+N-1; seg[node][0]-=val; seg[node][1]-=val; node>>=1; while(node>0) { seg[node]=merge(seg[node<<1],seg[node<<1|1]); node>>=1; } } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
faacd0d03241a7cf5d3e3bb4f515433f
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; public class Solution { static MyScanner str = new MyScanner(); // static Scanner str = new Scanner(System.in); public static void main(String[] args) throws IOException { int T = i(); while (T-- > 0) { solve(); } } static void solve() throws IOException { int n = i(), xor = 0; int a[] = new int[n]; for (int i = 0; i < n - 2; i++) { xor ^= i; a[i] = i; } if (xor == 0) { a[0] = n - 2; xor ^= a[0]; a[n - 2] = (1 << 30); a[n - 1] = xor ^ (1 << 30); } else { a[n - 2] = (1 << 30); a[n - 1] = xor ^ (1 << 30); } System.out.println(Arrays.toString(a).replace("[", "").replace("]", "").replace(",", "")); } public static int i() throws IOException { return str.nextInt(); } public static long l() throws IOException { return str.nextLong(); } public static double d() throws IOException { return str.nextDouble(); } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
70018783314388d2d0bea4c786507b93
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; public class Solution { // static MyScanner str = new MyScanner(); static Scanner str = new Scanner(System.in); public static void main(String[] args) throws IOException { int T = i(); while (T-- > 0) { solve(); } } static void solve() throws IOException { int n = i(), xor = 0; int a[] = new int[n]; for (int i = 0; i < n - 2; i++) { xor ^= i; a[i] = i; } if (xor == 0) { a[0] = n - 2; xor ^= a[0]; a[n - 2] = (1 << 30); a[n - 1] = xor ^ (1 << 30); } else { a[n - 2] = (1 << 30); a[n - 1] = xor ^ (1 << 30); } System.out.println(Arrays.toString(a).replace("[", "").replace("]", "").replace(",", "")); } public static int i() throws IOException { return str.nextInt(); } public static long l() throws IOException { return str.nextLong(); } public static double d() throws IOException { return str.nextDouble(); } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
90dd4fc6bca46778aea1a3fc6dea0016
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; public class Solution { // static MyScanner str = new MyScanner(); static Scanner str = new Scanner(System.in); public static void main(String[] args) throws IOException { int T = i(); while (T-- > 0) { solve(); } } static void solve() throws IOException { int n = i(), xor = 0; int a[] = new int[n]; for (int i = 0; i < n - 2; i++) { xor ^= i; a[i] = i; } if (xor == 0) { a[0] = n - 2; xor ^= a[0]; a[n - 2] = (1 << 30); a[n - 1] = xor | (1 << 30); } else { a[n - 2] = (1 << 30); a[n - 1] = xor | (1 << 30); } System.out.println(Arrays.toString(a).replace("[", "").replace("]", "").replace(",", "")); } public static int i() throws IOException { return str.nextInt(); } public static long l() throws IOException { return str.nextLong(); } public static double d() throws IOException { return str.nextDouble(); } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
4ffe29132b663110c41fc0b5716c1c53
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
/*############################################################################################################ ########################################## >>>> Diaa12360 <<<< ############################################### ########################################### Just Nothing ################################################# #################################### If You Need it, Fight For IT; ######################################### ###############################################.-. 1 5 9 2 .-.################################################ ############################################################################################################*/ import java.io.*; import java.math.BigInteger; import java.util.*; public class Solution { static final int maxN = 1000000000; static int dx[] = {1, 0, 0, -1}; static int dy[] = {0, -1, 1, 0}; public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // in = new BufferedReader(new FileReader("in.text")); StringBuilder out = new StringBuilder(); StringTokenizer tk; int t = anInt(in.readLine()); while (t-- > 0) { int n = anInt(in.readLine()); int xorOdd = 0, xorEven = 0, x = 1; for (int i = 0; i < n - 2; i++) { if ((i & 1) == 1) { if ((xorOdd ^ xorEven ^ x) != 1) x++; xorOdd ^= x; out.append(x).append(' '); x++; } else { if ((xorOdd ^ xorEven ^ x) != 1) x++; xorEven ^= x; out.append(x).append(' '); x++; } } // xorEven ^= (x * 2) ^ xorOdd ^ xorEven; // xorOdd ^= 2*x; out.append((x * 2) ^ xorOdd ^ xorEven).append(' '); out.append(2 * x).append('\n'); // out.append(xorEven).append(' ').append(xorOdd).append('\n'); } System.out.println(out); } static boolean v[][]; static int solve(int cuX, int cuY, int sx, int sy, int n, int m, int d, int count) { if (cuX == n && cuY == m) { return count; } v[cuX][cuY] = true; int c = 0; for (int i = 0; i < 4; i++) { int nextX = cuX + dx[i]; int nextY = cuY + dy[i]; if (nextX > n || nextY > m || nextX < 1 || nextY < 1 || v[nextX][nextY]) continue; if (Math.abs(nextY - sy) + Math.abs(nextX - sx) <= d) continue; c++; return solve(nextX, nextY, sx, sy, n, m, d, count + 1); } if (c == 0) { return -1; } return -1; } /* 3 2 3 1 3 0 2 3 1 3 1 5 5 3 4 2 */ static int lcm(int a, int b) { return a / gcd(a, b) * b; } static int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } //all primes static ArrayList<Integer> primes; static boolean[] primesB; //sieve algorithm static void sieve(int n) { primes = new ArrayList<>(); primesB = new boolean[n + 1]; for (int i = 2; i <= n; i++) { primesB[i] = true; } for (int i = 2; i * i <= n; i++) { if (primesB[i]) { for (int j = i * i; j <= n; j += i) { primesB[j] = false; } } } for (int i = 0; i <= n; i++) { if (primesB[i]) { primes.add(i); } } } // Function to find gcd of array of // numbers static int findGCD(int[] arr, int n) { int result = arr[0]; for (int element : arr) { result = gcd(result, element); if (result == 1) { return 1; } } return result; } private static int anInt(String s) { return Integer.parseInt(s); } } class Pair<K, V> implements Comparable<Pair<K, V>> { K first; V second; Pair(K f, V s) { first = f; second = s; } @Override public int compareTo(Pair<K, V> o) { return 0; } } class PairInt implements Comparable<PairInt> { int first; int second; PairInt(int f, int s) { first = f; second = s; } @Override public int compareTo(PairInt o) { if (this.first > o.first) { return 1; } else if (this.first < o.first) return -1; else { if (this.second < o.second) return 1; else if (this.second == o.second) return -1; return 0; } } @Override public String toString() { return "<" + first + ", " + second + ">"; } } /* 5 1 5 4 3 2 1 1 4 5 3 1 2 3 5 4 1 3 4 5 3 5 5 3 1 2 2 2 1 1 4 2 5 1 5 5 2 1 1 1 2 1 2 3 4 5 10 1 3 1 5 2 3 5 7 4 3 5 1 1 1 1 2 1 4 2 4 1 2 4 1 3 1 3 3 3 3 2 5 4 1 5 3 2 1 1 5 1 2 3 3 5 3 3 6 8 4 */
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
23e11b0e95f5902a33a60c0ea786e3b5
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
/*############################################################################################################ ########################################## >>>> Diaa12360 <<<< ############################################### ########################################### Just Nothing ################################################# #################################### If You Need it, Fight For IT; ######################################### ###############################################.-. 1 5 9 2 .-.################################################ ############################################################################################################*/ import java.io.*; import java.math.BigInteger; import java.util.*; public class Solution { static final int maxN = 1000000000; static int dx[] = {1, 0, 0, -1}; static int dy[] = {0, -1, 1, 0}; public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // in = new BufferedReader(new FileReader("in.text")); StringBuilder out = new StringBuilder(); StringTokenizer tk; int t = anInt(in.readLine()); while (t-- > 0) { int n = anInt(in.readLine()); int xorOdd = 0, xorEven = 0, x = 1; for (int i = 0; i < n - 2; i++) { if ((i & 1) == 1) { if ((xorOdd ^ xorEven ^ x) == 0) x++; xorOdd ^= x; out.append(x).append(' '); x++; } else { if ((xorOdd ^ xorEven ^ x) == 0) x++; xorEven ^= x; out.append(x).append(' '); x++; } } out.append((x * 2) ^ xorOdd ^ xorEven).append(' '); out.append(2 * x).append('\n'); } System.out.println(out); } static boolean v[][]; static int solve(int cuX, int cuY, int sx, int sy, int n, int m, int d, int count) { if (cuX == n && cuY == m) { return count; } v[cuX][cuY] = true; int c = 0; for (int i = 0; i < 4; i++) { int nextX = cuX + dx[i]; int nextY = cuY + dy[i]; if (nextX > n || nextY > m || nextX < 1 || nextY < 1 || v[nextX][nextY]) continue; if (Math.abs(nextY - sy) + Math.abs(nextX - sx) <= d) continue; c++; return solve(nextX, nextY, sx, sy, n, m, d, count + 1); } if (c == 0) { return -1; } return -1; } /* 3 2 3 1 3 0 2 3 1 3 1 5 5 3 4 2 */ static int lcm(int a, int b) { return a / gcd(a, b) * b; } static int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } //all primes static ArrayList<Integer> primes; static boolean[] primesB; //sieve algorithm static void sieve(int n) { primes = new ArrayList<>(); primesB = new boolean[n + 1]; for (int i = 2; i <= n; i++) { primesB[i] = true; } for (int i = 2; i * i <= n; i++) { if (primesB[i]) { for (int j = i * i; j <= n; j += i) { primesB[j] = false; } } } for (int i = 0; i <= n; i++) { if (primesB[i]) { primes.add(i); } } } // Function to find gcd of array of // numbers static int findGCD(int[] arr, int n) { int result = arr[0]; for (int element : arr) { result = gcd(result, element); if (result == 1) { return 1; } } return result; } private static int anInt(String s) { return Integer.parseInt(s); } } class Pair<K, V> implements Comparable<Pair<K, V>> { K first; V second; Pair(K f, V s) { first = f; second = s; } @Override public int compareTo(Pair<K, V> o) { return 0; } } class PairInt implements Comparable<PairInt> { int first; int second; PairInt(int f, int s) { first = f; second = s; } @Override public int compareTo(PairInt o) { if (this.first > o.first) { return 1; } else if (this.first < o.first) return -1; else { if (this.second < o.second) return 1; else if (this.second == o.second) return -1; return 0; } } @Override public String toString() { return "<" + first + ", " + second + ">"; } } /* 5 1 5 4 3 2 1 1 4 5 3 1 2 3 5 4 1 3 4 5 3 5 5 3 1 2 2 2 1 1 4 2 5 1 5 5 2 1 1 1 2 1 2 3 4 5 10 1 3 1 5 2 3 5 7 4 3 5 1 1 1 1 2 1 4 2 4 1 2 4 1 3 1 3 3 3 3 2 5 4 1 5 3 2 1 1 5 1 2 3 3 5 3 3 6 8 4 */
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
bf2ef8ed407384f88a051e163d62b3e1
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
/* || श्री राम समर्थ || || जय जय रघुवीर समर्थ || */ import java.io.*; import java.util.*; import static java.util.Arrays.sort; public class CodeforcesTemp { static Reader scan = new Reader(); static FastPrinter out = new FastPrinter(); public static void main(String[] args) throws IOException { int tt= scan.nextInt(); // int tt=1; outer:for (int tc =0; tc < tt; tc++) { int n= scan.nextInt(); if(n==3){ out.println("2 1 3"); out.flush(); continue ; } int[] arr=new int[n]; n-=2; int cnt=1; for (int i = 0; i < n; i+=2) { arr[i]=cnt; ++cnt; } for (int i = 1; i < n; i+=2) { arr[i]=(arr[i-1] | (1<<26)); ++cnt; } int xor1=0; int xor2=0; for (int i = 0; i < n; i+=2) { xor1=xor1^arr[i]; } for (int i = 1; i < n; i+=2) { xor2=xor2^arr[i]; } if(xor1==xor2){ arr[n+1]=(1<<28)+1; arr[n]=(1<<28); arr[0]=0; out.printArray(arr); out.flush(); continue ; } arr[n+1]=xor1 | (1<<28); arr[n]=xor2 | (1<<28); out.printArray(arr); out.flush(); } out.flush(); out.close(); } static class Reader { private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public Reader(InputStream in) { this.in = in; } public Reader() { this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("not number")); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("not number")); } } } } throw new ArithmeticException( String.format(" overflows long.")); } n = n * 10 + digit; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(long length) { long[] array = new long[(int) length]; for (int i = 0; i < length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map) { long[] array = new long[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = this.nextInt(); return array; } public int[][] nextIntArrayMulti(int length, int width) { int[][] arrays = new int[width][length]; for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) arrays[j][i] = this.nextInt(); } return arrays; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width) { long[][] mat = new long[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width) { int[][] mat = new int[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width) { double[][] mat = new double[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width) { char[][] mat = new char[height][width]; for (int h = 0; h < height; h++) { String s = this.next(); for (int w = 0; w < width; w++) { mat[h][w] = s.charAt(w); } } return mat; } } static class FastPrinter extends PrintWriter { public FastPrinter(PrintStream stream) { super(stream); } public FastPrinter() { super(System.out); } private static String dtos(double x, int n) { StringBuilder sb = new StringBuilder(); if (x < 0) { sb.append('-'); x = -x; } x += Math.pow(10, -n) / 2; sb.append((long) x); sb.append("."); x -= (long) x; for (int i = 0; i < n; i++) { x *= 10; sb.append((int) x); x -= (int) x; } return sb.toString(); } @Override public void print(float f) { super.print(dtos(f, 20)); } @Override public void println(float f) { super.println(dtos(f, 20)); } @Override public void print(double d) { super.print(dtos(d, 20)); } @Override public void println(double d) { super.println(dtos(d, 20)); } public void printArray(int[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(int[] array) { this.printArray(array, " "); } public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsInt(array[i])); super.print(separator); } super.println(map.applyAsInt(array[n - 1])); } public void printArray(int[] array, java.util.function.IntUnaryOperator map) { this.printArray(array, " ", map); } public void printArray(long[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(long[] array) { this.printArray(array, " "); } public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsLong(array[i])); super.print(separator); } super.println(map.applyAsLong(array[n - 1])); } public void printArray(long[] array, java.util.function.LongUnaryOperator map) { this.printArray(array, " ", map); } public void printMatrix(int[][] arr) { for (int i = 0; i < arr.length; i++) { this.printArray(arr[i]); } } public void printCharMatrix(char[][] arr, int n, int m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { this.print(arr[i][j] + " "); } this.println(); } } } static Random __r = new Random(); static int randInt(int min, int max) { return __r.nextInt(max - min + 1) + min; } static void reverse(int[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(long[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(double[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] arr, int i, int j) { while (i < j) { char temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void reverse(int[] arr, int i, int j) { while (i < j) { int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void reverse(long[] arr, int i, int j) { while (i < j) { long temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void shuffle(int[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(long[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } private static int getlowest(int l) { if (l >= 1000000000) return 1000000000; if (l >= 100000000) return 100000000; if (l >= 10000000) return 10000000; if (l >= 1000000) return 1000000; if (l >= 100000) return 100000; if (l >= 10000) return 10000; if (l >= 1000) return 1000; if (l >= 100) return 100; if (l >= 10) return 10; return 1; } static void shuffle(double[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void rsort(int[] a) { shuffle(a); sort(a); } static void rsort(long[] a) { shuffle(a); sort(a); } static void rsort(double[] a) { shuffle(a); sort(a); } static int[] copy(int[] a) { int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static long[] copy(long[] a) { long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static double[] copy(double[] a) { double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static char[] copy(char[] a) { char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
67b9dc4f39f91fe8af4f7f8b4d6e60d2
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
/* || श्री राम समर्थ || || जय जय रघुवीर समर्थ || */ import java.io.*; import java.util.*; import static java.util.Arrays.sort; public class CodeforcesTemp { static Reader scan = new Reader(); static FastPrinter out = new FastPrinter(); public static void main(String[] args) throws IOException { int tt= scan.nextInt(); // int tt=1; outer:for (int tc =0; tc < tt; tc++) { int n= scan.nextInt(); if(n==3){ out.println("2 1 3"); out.flush(); continue ; } int[] arr=new int[n]; int cnt=2; if((n/2)%2==0){ for (int i = 0; i < n; i+=2) { arr[i]=cnt; cnt++; } cnt-=1; if(n%2==1)--cnt; String s=Integer.toBinaryString(cnt); int len=s.length(); for (int i = 1; i < n; i+=2) { arr[i]=(arr[i-1] | 1<<len ); } if(n%2==1){ arr[n-1]=0; } }else{ if(n%2==0){ cnt=1; for (int i = 0; i < n; i+=2) { arr[i]=cnt; cnt++; } cnt-=2; String s=Integer.toBinaryString(cnt); int len=s.length(); for (int i = 1; i < n; i+=2) { arr[i]=(arr[i-1] | 1<<len ); } arr[0]=0; arr[n-2]=(1<<26)+1; arr[n-1]=(1<<26); }else{ cnt=2; for (int i = 0; i < n; i+=2) { arr[i]=cnt; cnt++; } cnt-=3; String s=Integer.toBinaryString(cnt); int len=s.length(); for (int i = 1; i < n; i+=2) { arr[i]=(arr[i-1] | 1<<len ); } arr[n-2]=(1<<26)+1; arr[n-3]=(1<<26); arr[n-1]=1; } } out.printArray(arr); out.flush(); } out.flush(); out.close(); } static class Reader { private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public Reader(InputStream in) { this.in = in; } public Reader() { this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("not number")); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("not number")); } } } } throw new ArithmeticException( String.format(" overflows long.")); } n = n * 10 + digit; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(long length) { long[] array = new long[(int) length]; for (int i = 0; i < length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map) { long[] array = new long[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = this.nextInt(); return array; } public int[][] nextIntArrayMulti(int length, int width) { int[][] arrays = new int[width][length]; for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) arrays[j][i] = this.nextInt(); } return arrays; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width) { long[][] mat = new long[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width) { int[][] mat = new int[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width) { double[][] mat = new double[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width) { char[][] mat = new char[height][width]; for (int h = 0; h < height; h++) { String s = this.next(); for (int w = 0; w < width; w++) { mat[h][w] = s.charAt(w); } } return mat; } } static class FastPrinter extends PrintWriter { public FastPrinter(PrintStream stream) { super(stream); } public FastPrinter() { super(System.out); } private static String dtos(double x, int n) { StringBuilder sb = new StringBuilder(); if (x < 0) { sb.append('-'); x = -x; } x += Math.pow(10, -n) / 2; sb.append((long) x); sb.append("."); x -= (long) x; for (int i = 0; i < n; i++) { x *= 10; sb.append((int) x); x -= (int) x; } return sb.toString(); } @Override public void print(float f) { super.print(dtos(f, 20)); } @Override public void println(float f) { super.println(dtos(f, 20)); } @Override public void print(double d) { super.print(dtos(d, 20)); } @Override public void println(double d) { super.println(dtos(d, 20)); } public void printArray(int[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(int[] array) { this.printArray(array, " "); } public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsInt(array[i])); super.print(separator); } super.println(map.applyAsInt(array[n - 1])); } public void printArray(int[] array, java.util.function.IntUnaryOperator map) { this.printArray(array, " ", map); } public void printArray(long[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(long[] array) { this.printArray(array, " "); } public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsLong(array[i])); super.print(separator); } super.println(map.applyAsLong(array[n - 1])); } public void printArray(long[] array, java.util.function.LongUnaryOperator map) { this.printArray(array, " ", map); } public void printMatrix(int[][] arr) { for (int i = 0; i < arr.length; i++) { this.printArray(arr[i]); } } public void printCharMatrix(char[][] arr, int n, int m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { this.print(arr[i][j] + " "); } this.println(); } } } static Random __r = new Random(); static int randInt(int min, int max) { return __r.nextInt(max - min + 1) + min; } static void reverse(int[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(long[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(double[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] arr, int i, int j) { while (i < j) { char temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void reverse(int[] arr, int i, int j) { while (i < j) { int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void reverse(long[] arr, int i, int j) { while (i < j) { long temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void shuffle(int[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(long[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } private static int getlowest(int l) { if (l >= 1000000000) return 1000000000; if (l >= 100000000) return 100000000; if (l >= 10000000) return 10000000; if (l >= 1000000) return 1000000; if (l >= 100000) return 100000; if (l >= 10000) return 10000; if (l >= 1000) return 1000; if (l >= 100) return 100; if (l >= 10) return 10; return 1; } static void shuffle(double[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void rsort(int[] a) { shuffle(a); sort(a); } static void rsort(long[] a) { shuffle(a); sort(a); } static void rsort(double[] a) { shuffle(a); sort(a); } static int[] copy(int[] a) { int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static long[] copy(long[] a) { long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static double[] copy(double[] a) { double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static char[] copy(char[] a) { char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
9fb17332e3553609a2114031ed1879f9
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; public class MainG { static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public boolean hasNext() { try { String string = reader.readLine(); if (string == null) { return false; } tokenizer = new StringTokenizer(string); return tokenizer.hasMoreTokens(); } catch (IOException e) { return false; } } } static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static void ini() { pow[0] = 1; for (int i = 1; i < 31; i++) { pow[i] = pow[i-1] * 2; } } static String yes = "YES"; static String no = "NO"; static int ipInf = Integer.MAX_VALUE-5; static int inInf = Integer.MIN_VALUE+5; static long lpInf = Long.MAX_VALUE - 5; static long lnInf = Long.MIN_VALUE + 5; public static void main(String[] args) { int t = in.nextInt(); ini(); while (t -- > 0) { solve(); } out.close(); } static int[] pow = new int[31]; static void solve() { int n = in.nextInt(); int[] res = new int[n]; int temp = 1; for (int i = 0; i < n; i++) { if (i % 2 == 0) { res[i] = temp + pow[30]; } else { res[i] = temp; temp ++; } } if (n % 2 == 0 && n % 4 != 0) { res[n-1] += pow[30] + pow[29]; res[n-4] += pow[29]; } else if (n % 4 == 3) { res[n-1] = pow[30]; } else if (n % 4 == 1) { res[n-1] = 0; } printArr(res); // checkArr(res); } static void checkArr(int[] arr) { int _1 = 0, _2 = 0; int n = arr.length; for (int i = 0; i < n; i++) { if (i % 2 == 1) { _1 ^= arr[i]; } else { _2 ^= arr[i]; } } out.println(_1 == _2 ? yes : no); } static void printArr (int[] arr) { int n = arr.length; if (n == 0) return; for (int i = 0; i < n-1; i++) { out.print(arr[i] + " "); } out.println(arr[n-1]); } static void printArr (long[] arr) { int n = arr.length; if (n == 0) return; for (int i = 0; i < n-1; i++) { out.print(arr[i] + " "); } out.println(arr[n-1]); } static long _gcd (long a, long b) { long temp; while (true) { temp = a % b; if (temp == 0) return b; a = b; b = temp; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
27250c6455528d1d1ab5266885505b4f
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
// package faltu; import java.util.*; import java.util.Map.Entry; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; public class Main { // ***********************MATHS--STARTS************************************************* // private static ArrayList<Long> get_divisor(long x) { ArrayList<Long>a=new ArrayList<Long>(); for(long i=2;i*i<=x;i++) { if(x%i==0) { a.add((long) i); if(x/i!=i)a.add(x/i); } } return a; } private static int CntOfFactor(long x) { ArrayList<Long>a=new ArrayList<Long>(); for(long i=1;i*i<=x;i++) { if(x%i==0) { a.add((long) i); if(x/i!=i)a.add(x/i); } } return a.size(); } static long[] sieve; static long[] smallestPrime; public static void sieve() { int n=4000000+1; sieve=new long[n]; smallestPrime=new long[n]; sieve[0]=1; sieve[1]=1; for(int i=2;i<n;i++){ sieve[i]=i; smallestPrime[i]=i; } for(int i=2;i*i<n;i++){ if(sieve[i]==i){ for(int j=i*i;j<n;j+=i){ if(sieve[j]==j)sieve[j]=1; if(smallestPrime[j]==j||smallestPrime[j]>i)smallestPrime[j]=i; } } } } static long nCr(long n,long r,long MOD) { computeFact(n, MOD); if(n<r)return 0; if(r==0)return 1; return fact[(int) n]*mod_inv(fact[(int) r],MOD)%MOD*mod_inv(fact[(int) (n-r)],MOD)%MOD; } static long[]fact; static void computeFact(long n,long MOD) { fact=new long[(int)n+1]; fact[0]=1; for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i%MOD)%MOD; } static long bin_expo(long a,long b,long MOD) { if(b == 0)return 1; long ans = bin_expo(a,b/2,MOD); ans = (ans*ans)%MOD; if(b % 2!=0){ ans = (ans*a)%MOD; } return ans%MOD; } static int ceil(int x, int y) {return (x % y == 0 ? x / y : (x / y + 1));} static long ceil(long x, long y) {return (x % y == 0 ? x / y : (x / y + 1));} static long mod_add(long a, long b, long m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} static long mod_mul(long a, long b, long m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} static long mod_sub(long a, long b, long m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} static long mod_inv(long n,long p) {return bin_expo(n,p-2,p);} static long gcd(long a, long b){if (a == 0) {return b;}return gcd(b % a, a); } static int gcd(int a, int b){if (a == 0) {return b; }return gcd(b % a, a); } static long lcm(long a,long b){return (a / gcd(a, b)) * b;} static long min(long x,long y) {return Math.min(x, y);}static long max(long x,long y) {return Math.max(x, y);} static int min(int x,int y) {return Math.min(x, y);}static int max(int x,int y) {return Math.max(x, y);} static ArrayList<String>powof2s; static void powof2S() { long i=1; while(i<(long)2e18) { powof2s.add(String.valueOf(i)); i*=2; } } static long power(long a, long b){ a %=MOD;long out = 1; while (b > 0) { if((b&1)!=0)out = out * a % MOD; a = a * a % MOD; b >>= 1; a*=a; } return out; } static boolean coprime(int a, long l){return (gcd(a, l) == 1);} // ****************************MATHS-ENDS***************************************************** // ***********************BINARY-SEARCH STARTS*********************************************** public static int upperBound(long[] arr, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(arr[mid]<=m) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(long[] a, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(a[mid]<m) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(ArrayList<Integer> ar,int k){ int s=0,e=ar.size(); while (s!=e){ int mid = s+e>>1; if (ar.get(mid) <k)s=mid+1; else e=mid; } if(s==ar.size())return -1; return s; } public static int upperBound(ArrayList<Integer> ar,int k){ int s=0,e=ar.size(); while (s!=e){ int mid = s+e>>1; if (ar.get(mid) <=k)s=mid+1; else e=mid; } if(s==ar.size())return -1; return s; } public static long getClosest(long val1, long val2,long target){if (target - val1 >= val2 - target)return val2; else return val1;} static void ruffleSort(long[] a) { int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { long oi=r.nextInt(n), temp=a[i]; a[i]=a[(int)oi]; a[(int)oi]=temp; } Arrays.sort(a); } static void ruffleSort(int[] a){ int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n), temp=a[i]; a[i]=a[oi]; a[oi]=temp; } Arrays.sort(a); } int ceilIndex(int input[], int T[], int end, int s){ int start = 0; int middle; int len = end; while(start <= end){ middle = (start + end)/2; if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){ return middle+1; }else if(input[T[middle]] < s){ start = middle+1; }else{ end = middle-1; } } return -1; } static int lowerLimitBinarySearch(ArrayList<Long> v,long k) { int n =v.size(); int first = 0,second = n; while(first <second) { int mid = first + (second-first)/2; if(v.get(mid) > k) { second = mid; }else { first = mid+1; } } if(first < n && v.get(first) < k) { first++; } return first; //1 index } public static int searchindex(long arr[], long t){int index = Arrays.binarySearch(arr, t);return (index < 0) ? -1 : index;} public static long[] sort(long[] a) {ArrayList<Long> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;} public static int[] sort(int[] a) {ArrayList<Integer> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;} // *******************************BINARY-SEARCH ENDS*********************************************** // *********************************GRAPHS-STARTS**************************************************** // *******----SEGMENT TREE IMPLEMENT---***** // -------------START--------------- void buildTree (int[] arr,int[] tree,int start,int end,int treeNode){ if(start==end){ tree[treeNode]=arr[start]; return; } buildTree(arr,tree,start,end,2*treeNode); buildTree(arr,tree,start,end,2*treeNode+1); tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1]; } void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value){ if(start==end){ arr[idx]=value; tree[treeNode]=value; return; } int mid=(start+end)/2; if(idx>mid)updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value); else updateTree(arr,tree,start,mid,2*treeNode,idx,value); tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1]; } long query(int[]arr,int[]tree,int start,int end,int treeNode,int qleft,int qright) { if(start>=qleft&&end<=qright)return tree[treeNode]; if(start>qright||end<qleft)return 0; int mid=(start+end)/2; long valLeft=query(arr,tree,start,mid-1,treeNode*2,qleft,qright); long valRight=query(arr,tree,mid+1,end,treeNode*2+1,qleft,qright); return valLeft+valRight; } // -------------ENDS--------------- //***********************DSU IMPLEMENT START************************* static int parent[]; static int rank[]; static int[]Size; static void makeSet(int n){ parent=new int[n]; rank=new int[n]; Size=new int[n]; for(int i=0;i<n;i++){ parent[i]=i; rank[i]=0; Size[i]=1; } } static void union(int u,int v){ u=findpar(u); v=findpar(v); if(u==v)return; if(rank[u]<rank[v]) { parent[u]=v; Size[v]+=Size[u]; } else if(rank[v]<rank[u]) { parent[v]=u; Size[u]+=Size[v]; } else{ parent[v]=u; rank[u]++; Size[u]+=Size[v]; } } private static int findpar(int node){ if(node==parent[node])return node; return parent[node]=findpar(parent[node]); } // *********************DSU IMPLEMENT ENDS************************* // ****__________PRIMS ALGO______________________**** private static int prim(ArrayList<node>[] adj,int N,int node) { int key[] = new int[N+1]; int parent[] = new int[N+1]; boolean mstSet[] = new boolean[N+1]; for(int i = 0;i<N;i++) { key[i] = 100000000; mstSet[i] = false; } PriorityQueue<node> pq = new PriorityQueue<node>(N, new node()); key[node] = 0; parent[node] = -1; pq.add(new node( node,key[node])); for(int i = 0;i<N-1;i++) { int u = pq.poll().getV(); mstSet[u] = true; for(node it: adj[u]) { if(mstSet[it.getV()] == false && it.getW() < key[it.getV()]) { parent[it.getV()] = u; key[it.getV()] = (int) it.getW(); pq.add(new node(it.getV(), key[it.getV()])); } } } int sum=0; for(int i=1;i<N;i++) { System.out.println(key[i]); sum+=key[i]; } System.out.println(sum); return sum; } // ****____________DIJKSTRAS ALGO___________**** static int[]dist; static int dijkstra(int u,int n,ArrayList<node>adj[]) { long[]path=new long[n]; dist=new int[n]; Arrays.fill(dist,Integer.MAX_VALUE); dist[u]=0; path[0]=1; PriorityQueue<node>pq=new PriorityQueue<node>(new node()); pq.add(new node(u,0)); while(!pq.isEmpty()) { node v=pq.poll(); if(dist[v.getV()]<v.getW())continue; for(node it:adj[v.getV()]) { if(dist[it.getV()]>it.getW()+dist[v.getV()]) { dist[it.getV()]=(int) (it.getW()+dist[v.getV()]); pq.add(new node(it.getV(),dist[it.getV()])); path[it.getV()]=path[v.getV()]; } else if(dist[it.getV()]==it.getW()+dist[v.getV()]) { path[it.getV()]+=path[v.getV()]; } } } int sum=0; for(int i=1;i<n;i++){ System.out.println(dist[i]); sum+=dist[i]; } return sum; } private static void setGraph(int n,int m){ vis=new boolean[n+1]; indeg=new int[n+1]; // adj=new ArrayList<ArrayList<Integer>>(); // for(int i=0;i<=n;i++)adj.add(new ArrayList<>()); // for(int i=0;i<m;i++){ // int u=s.nextInt(),v=s.nextInt(); // adj.get(u).add(v); // adj.get(v).add(u); // } adj=new ArrayList[n+1]; // backadj=new ArrayList[n+1]; for(int i=0;i<=n;i++){ adj[i]=new ArrayList<Integer>(); // backadj[i]=new ArrayList<Integer>(); } for(int i=0;i<m;i++){ int u=s.nextInt(),v=s.nextInt(); adj[u].add(v); adj[v].add(u); // backadj[v].add(u); indeg[v]++; indeg[u]++; } // weighted adj // adj=new ArrayList[n+1]; // for(int i=0;i<=n;i++){ // adj[i]=new ArrayList<node>(); // } // for(int i=0;i<m;i++){ // int u=s.nextInt(),v=s.nextInt(); // long w=s.nextInt(); // adj[u].add(new node(v,w)); //// adj[v].add(new node(u,w)); // } } // *********************************GRAPHS-ENDS**************************************************** static int[][] dirs8 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}; static int[][] dirs4 = {{1,0},{-1,0},{0,1},{0,-1}}; //d-u-r-l static long MOD=(long) (1e9+7); static int prebitsum[][]; static boolean[] vis; static int[]indeg; // static ArrayList<ArrayList<Integer>>adj; static ArrayList<Integer> adj[]; static ArrayList<Integer> backadj[]; static FastReader s = new FastReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { // sieve(); // computeFact((int)1e7+1,MOD); // prebitsum=new int[2147483648][31]; // presumbit(prebitsum); // powof2S(); // // try { int tt = s.nextInt(); // int tt=1; for(int i=1;i<=tt;i++) { solver(); } out.close(); // catch(Exception e) {return;} } private static void solver() { int n=s.nextInt(); long max=0; if(n%4==0) { out.print("0"+" "); n-=1; max=2; } if(n%4==1) { out.print("0"+" "); max=2; n-=1; } else if(n%4==2) { out.print(1+" "+3+" "+2+" "+8+" "+14+" "+6+" "); max=16; n-=6; } else if(n%4==3) { out.print(1+" "+3+" "+2+" "); max=4; n-=3; } if(n>0) { for(long i=0;i<n;i++) { out.print(max+" "); max++; } }out.println(); } /* *********************BITS && TOOLS &&DEBUG STARTS***********************************************/ static boolean issafe(int i, int j, int r,int c,boolean[][]vis){ if (i < 0 || j < 0 || i >= r || j >= c||vis[i][j]==true)return false; else return true; } static void presumbit(int[][]prebitsum) { for(int i=1;i<=200000;i++) { int z=i; int j=0; while(z>0) { if((z&1)==1) { prebitsum[i][j]+=(prebitsum[i-1][j]+1); }else { prebitsum[i][j]=prebitsum[i-1][j]; } z=z>>1; j++; } } } static void countOfSetBit(long[]a) { for(int j=30;j>=0;j--) { int cnt=0; for(long i:a) { if((i&1<<j)==1)cnt++; } // printing the current no set bit in all array element System.out.println(cnt); } } public static String revStr(String str){String input = str;StringBuilder input1 = new StringBuilder();input1.append(input);input1.reverse();return input1.toString();} static void printA(long[] x) {for(int i=0;i<x.length;i++)System.out.print(x[i]+" ");System.out.println();} static void printA(int[] x) {for(int i=0;i<x.length;i++)System.out.print(x[i]+" ");System.out.println();} static void pc2d(boolean[][] vis) { int n=vis.length; int m=vis[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(vis[i][j]+" "); } System.out.println(); } } static void pi2d(char[][] a) { int n=a.length; int m=a[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } static void p1d(int[]a) { for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } // *****************BITS && TOOLS &&DEBUG ENDS*********************************************** } // **************************I/O************************* class FastReader { public BufferedReader reader; public StringTokenizer tokenizer; public FastReader(InputStream stream) {reader = new BufferedReader(new InputStreamReader(stream), 32768);tokenizer = null;} public String next() {while (tokenizer == null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(reader.readLine());} catch (IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken();} public int nextInt(){ return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() {String str = "";try {str = reader.readLine();}catch (IOException e) {e.printStackTrace();}return str;} public int[] rdia(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = nextInt();return a;} public long[] rdla(int n) {long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;} public Integer[] rdIa(int n) {Integer[] a = new Integer[n];for (int i = 0; i < n; i++) a[i] =nextInt();return a;} public Long[] rdLa(int n) {Long[] a = new Long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;} } class dsu{ int n; static int parent[]; static int rank[]; static int[]Size; public dsu(int n) {this.n=n;this.parent=new int[n];this.rank=new int[n];this.Size=new int[n]; for(int i=0;i<n;i++){parent[i]=i;rank[i]=0;Size[i]=1;} } static int findpar(int node) {if(node==parent[node])return node;return parent[node]=findpar(parent[node]);} static void union(int u,int v){ u=findpar(u);v=findpar(v); if(u!=v) { if(rank[u]<rank[v]) {parent[u]=v;Size[v]+=Size[u];} else if(rank[v]<rank[u]) {parent[v]=u;Size[u]+=Size[v];} else{parent[v]=u;rank[u]++;Size[u]+=Size[v];} } } } class pair{ int x;int y; long u,v; public pair(int x,int y){this.x=x;this.y=y;} public pair(long u,long v) {this.u=u;this.v=v;} } class Tuple{ String str;int x;int y; public Tuple(String str,int x,int y) { this.str=str; this.x=x; this.y=y; } } class node implements Comparator<node>{ private int v; private long w; node(int _v, long _w) { v = _v; w = _w; } node() {} int getV() { return v; } long getW() { return w; } @Override public int compare(node node1, node node2) { if (node1.w < node2.w) return -1; if (node1.w > node2.w) return 1; return 0; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
a24d07b3871ecfc2ffda6e5990eb5188
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
// Mahakal // Remainder: Agar ni ban raha to demotivate ni hona. Yehi chance hai sikhne ka. import java.util.*; import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Main { static PrintWriter out = new PrintWriter(System.out); static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch (IOException e){ e.printStackTrace(); } return str; } } static FastReader sc; public static void main(String[] args) { solve(); } public static void solve() { sc = new FastReader(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int s = n; ArrayList<Integer> arr = new ArrayList<>(); int i = 0; int xor = 0; while(n-->2) { arr.add(i); xor^=i; i++; } n = s; if(xor==0) { arr = new ArrayList<>(); i = 1; xor = 0; while(n-->2) { arr.add(i); xor^=i; i++; } } arr.add((1<<30)); arr.add(xor^(1<<30)); for(int ele:arr) print(ele+" "); println(); } out.flush(); out.close(); } public static int dir4[][] = {{1,0},{0,1},{-1,0},{0,-1}}; public static int dir8[][] = {{1,0},{0,1},{-1,0},{0,-1},{-1,-1},{-1,1},{1,1},{1,-1}}; public static int lowerbound(int l,int r,int a[],int val) { int ans = l-1; while(l<=r) { int mid = l+(r-l)/2; if(a[mid]<val) { ans = mid; l = mid+1; }else r =mid-1; } return ans; } // 2 // 1 2 2 2 3 4 4 5 5 5 public static int dis(int x,int y) { return Math.abs(x-y); } public static class pair{ int v1; int v2; pair(int v1,int v2){ this.v1 = v1; this.v2 = v2; } } public static class graph{ int v; int maxbit; ArrayList<int[]> edgelist = new ArrayList<>(); ArrayList<int[]> adj[]; public static int[][] table; graph(int v){ this.v = v; adj = new ArrayList[v]; for(int i=0;i<v;i++) adj[i] = new ArrayList<>(); maxbit = 19; } public void addD(int f,int t){ int a[] = {f,t}; adj[f].add(a); edgelist.add(new int[] {f,t}); } public void addUD(int f,int t) { addD(f,t); addD(t,f); } public void addD(int f,int t,int w){ int a[] = {f,t,w}; adj[f].add(a); edgelist.add(new int[] {f,t,w}); } public void addUD(int f,int t,int w) { addD(f,t,w); addD(t,f,w); } public void printEdgelist() { for(int ele[]:edgelist) { println(ele); } } public void parentArray(int par[],int src,int parent) { for(int ele[]:adj[src]) { int t = ele[1]; if(t==parent) continue; par[t] = src; parentArray(par,t,src); } } public boolean IsBipartite(int i,boolean visited[]) { int color[] = new int[v]; Arrays.fill(color, -1); Queue<int[]> queue = new ArrayDeque<>(); queue.add(new int[] {i,1,-1}); while(queue.size()>0) { int top[] = queue.poll(); int src = top[0]; int pc = top[1]; int parent = top[2]; visited[src] = true; if(color[src]!=-1) { if(color[src]==pc) return false; }else color[src] = 1-pc; for(int ele[]:adj[src]) { int t = ele[1]; if(t==parent) continue; else { if(!visited[t]) queue.add(new int[] {t,color[src],src}); } } } return true; } public void printGraph() { for(int i=0;i<v;i++) { out.print(i+" - "); for(int ele[]:adj[i]) { out.print(ele[1]+" "); } out.println(); } } public void fillLevel(int src,int d,int level[],int parent) { level[src] = d; for(int ele[]:this.adj[src]) { int t = ele[1]; if(t==parent) continue; fillLevel(t,d+1,level,src); } } public void LcaTable(int parent[]) { table = new int[maxbit+1][v]; table[0] = parent; for(int i=1;i<=maxbit;i++) { for(int j=0;j<v;j++) { table[i][j] = table[i-1][table[i-1][j]]; } } } public int getLCA(int u,int v,int level[],int parent[]) { if(level[u]>level[v]) { int temp = u; u = v; v = temp; } int k = level[v]-level[u]; for(int i=0;i<maxbit;i++) { int bit = 1<<i; if((bit&k)>0) { v = table[i][v]; } } if(v==u) return u; for(int i=maxbit;i>=0;i--) { int p1 = table[i][u]; int p2 = table[i][v]; if(p1==p2) continue; else { u = p1; v = p2; } } return table[0][u]; } } //============= For loop bhi ni likha jaa raha====================== public static int[] Intfor(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = sc.nextInt(); return a; } public static long[] Longfor(int n) { long a[] = new long[n]; for(int i=0;i<n;i++) a[i] = sc.nextLong(); return a; } public static double[] Doublefor(int n) { double a[] = new double[n]; for(int i=0;i<n;i++) a[i] = sc.nextDouble(); return a; } public static String[] Stringfor(int n) { String a[] = new String[n]; for(int i=0;i<n;i++) a[i] = sc.next(); return a; } // =========================MergeSort Krdo===================================== public static int[] mergeSort(int arr[],int l,int r) { if(l>r) return new int[] {}; if(l==r) return new int[] {arr[l]}; int mid = l+(r-l)/2; int larr[] = mergeSort(arr,l,mid); int rarr[] = mergeSort(arr,mid+1,r); int newarr[] = merge(larr,rarr); return newarr; } public static int[] merge(int a[],int b[]) { int m[] = new int[a.length+b.length]; int i=0; int j=0; int ind = 0; while(i<a.length && j<b.length) { if(a[i]<b[j]) { m[ind] = a[i]; i++;ind++; }else { m[ind++] = b[j++]; } } while(i<a.length) m[ind++] = a[i++]; while(j<b.length) m[ind++] = b[j++]; return m; } // =================== Fast Print krne ke lie itna mehnat================== public static void print(String str) { out.print(str); } public static void println() { out.println(); } public static void print(int a) { out.print(a); } public static void print(char c) { out.print(c); } public static void print(char c[]) { out.print(Arrays.toString(c)); } public static void print(int a[]) { out.println(Arrays.toString(a)); } public static void print(String a[]) { out.print(Arrays.toString(a)); } public static void print(float a) { out.print(a); } public static void print(double a) { out.print(a); } public static void print(long a[]) { out.print(Arrays.toString(a)); } public static void println(String str) { out.println(str); } public static void println(boolean ap[][]) { for(boolean ele[]:ap) out.println(Arrays.toString(ele)); } public static void println(int a) { out.println(a); } public static void println(char c) { out.println(c); } public static void println(char c[]) { out.println(Arrays.toString(c)); } public static void println(int a[]) { out.println(Arrays.toString(a)); } public static void println(String a[]) { out.println(Arrays.toString(a)); } public static void println(float a) { out.println(a); } public static void println(double a) { out.println(a); } public static void println(long a[]) { out.println(Arrays.toString(a)); } public static void print(int a[][]) { for(int ele[]:a) { out.println(Arrays.toString(ele)); } out.println(); } public static void print(char a[][]) { for(char ele[]:a) { out.println(Arrays.toString(ele)); } } public static void print(long a[][]) { for(long ele[]:a) { out.println(Arrays.toString(ele)); } } public static void print(String a[][]) { for(String ele[]:a) { out.println(Arrays.toString(ele)); } } public static void println(long a) { out.println(a); } public static void println(Long a) { out.println(a); } public static void println(Integer a) { out.println(a); } public static void println(Long a[]) { out.println(Arrays.toString(a)); } public static void println(Integer a[]) { out.println(Arrays.toString(a)); } public static void println(boolean a[]) { out.println(Arrays.toString(a)); } public static void forEach(int a[]) { for(int ele:a) print(ele+" "); println(); } public static void forEach(long a[]) { for(long ele:a) print(ele+" "); println(); } public static void forEach(String a[]) { for(String ele:a) print(ele+" "); println(); } public static void forEach(char a[]) { for(char ele:a) print(ele+" "); println(); } public static void forEach(double a[]) { for(double ele:a) print(ele+" "); println(); } // ================================================== }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
7661ecfa4f4642462944388cbb3f93bc
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
// Mahakal // Remainder: Agar ni ban raha to demotivate ni hona. Yehi chance hai sikhne ka. import java.util.*; import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Main { static PrintWriter out = new PrintWriter(System.out); static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch (IOException e){ e.printStackTrace(); } return str; } } static FastReader sc; public static void main(String[] args) { solve(); } public static void solve() { sc = new FastReader(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); if(n%4==0) { int i = 2; while(n-->0) arr.add(i++); }else if(n%4==1) { int i= 2; while(n-->1) arr.add(i++); arr.add(0); }else if(n%4==2) { arr.add(2); arr.add(1); arr.add(3); arr.add(4); arr.add(12); arr.add(8); int i = 14; while(n-->6) { arr.add(i++); } }else { arr.add(2); arr.add(1); arr.add(3); int i = 4; while(n-->3) arr.add(i++); } for(int ele:arr) print(ele+" "); println(); } out.flush(); out.close(); } public static int dir4[][] = {{1,0},{0,1},{-1,0},{0,-1}}; public static int dir8[][] = {{1,0},{0,1},{-1,0},{0,-1},{-1,-1},{-1,1},{1,1},{1,-1}}; public static int lowerbound(int l,int r,int a[],int val) { int ans = l-1; while(l<=r) { int mid = l+(r-l)/2; if(a[mid]<val) { ans = mid; l = mid+1; }else r =mid-1; } return ans; } // 2 // 1 2 2 2 3 4 4 5 5 5 public static int dis(int x,int y) { return Math.abs(x-y); } public static class pair{ int v1; int v2; pair(int v1,int v2){ this.v1 = v1; this.v2 = v2; } } public static class graph{ int v; int maxbit; ArrayList<int[]> edgelist = new ArrayList<>(); ArrayList<int[]> adj[]; public static int[][] table; graph(int v){ this.v = v; adj = new ArrayList[v]; for(int i=0;i<v;i++) adj[i] = new ArrayList<>(); maxbit = 19; } public void addD(int f,int t){ int a[] = {f,t}; adj[f].add(a); edgelist.add(new int[] {f,t}); } public void addUD(int f,int t) { addD(f,t); addD(t,f); } public void addD(int f,int t,int w){ int a[] = {f,t,w}; adj[f].add(a); edgelist.add(new int[] {f,t,w}); } public void addUD(int f,int t,int w) { addD(f,t,w); addD(t,f,w); } public void printEdgelist() { for(int ele[]:edgelist) { println(ele); } } public void parentArray(int par[],int src,int parent) { for(int ele[]:adj[src]) { int t = ele[1]; if(t==parent) continue; par[t] = src; parentArray(par,t,src); } } public boolean IsBipartite(int i,boolean visited[]) { int color[] = new int[v]; Arrays.fill(color, -1); Queue<int[]> queue = new ArrayDeque<>(); queue.add(new int[] {i,1,-1}); while(queue.size()>0) { int top[] = queue.poll(); int src = top[0]; int pc = top[1]; int parent = top[2]; visited[src] = true; if(color[src]!=-1) { if(color[src]==pc) return false; }else color[src] = 1-pc; for(int ele[]:adj[src]) { int t = ele[1]; if(t==parent) continue; else { if(!visited[t]) queue.add(new int[] {t,color[src],src}); } } } return true; } public void printGraph() { for(int i=0;i<v;i++) { out.print(i+" - "); for(int ele[]:adj[i]) { out.print(ele[1]+" "); } out.println(); } } public void fillLevel(int src,int d,int level[],int parent) { level[src] = d; for(int ele[]:this.adj[src]) { int t = ele[1]; if(t==parent) continue; fillLevel(t,d+1,level,src); } } public void LcaTable(int parent[]) { table = new int[maxbit+1][v]; table[0] = parent; for(int i=1;i<=maxbit;i++) { for(int j=0;j<v;j++) { table[i][j] = table[i-1][table[i-1][j]]; } } } public int getLCA(int u,int v,int level[],int parent[]) { if(level[u]>level[v]) { int temp = u; u = v; v = temp; } int k = level[v]-level[u]; for(int i=0;i<maxbit;i++) { int bit = 1<<i; if((bit&k)>0) { v = table[i][v]; } } if(v==u) return u; for(int i=maxbit;i>=0;i--) { int p1 = table[i][u]; int p2 = table[i][v]; if(p1==p2) continue; else { u = p1; v = p2; } } return table[0][u]; } } //============= For loop bhi ni likha jaa raha====================== public static int[] Intfor(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = sc.nextInt(); return a; } public static long[] Longfor(int n) { long a[] = new long[n]; for(int i=0;i<n;i++) a[i] = sc.nextLong(); return a; } public static double[] Doublefor(int n) { double a[] = new double[n]; for(int i=0;i<n;i++) a[i] = sc.nextDouble(); return a; } public static String[] Stringfor(int n) { String a[] = new String[n]; for(int i=0;i<n;i++) a[i] = sc.next(); return a; } // =========================MergeSort Krdo===================================== public static int[] mergeSort(int arr[],int l,int r) { if(l>r) return new int[] {}; if(l==r) return new int[] {arr[l]}; int mid = l+(r-l)/2; int larr[] = mergeSort(arr,l,mid); int rarr[] = mergeSort(arr,mid+1,r); int newarr[] = merge(larr,rarr); return newarr; } public static int[] merge(int a[],int b[]) { int m[] = new int[a.length+b.length]; int i=0; int j=0; int ind = 0; while(i<a.length && j<b.length) { if(a[i]<b[j]) { m[ind] = a[i]; i++;ind++; }else { m[ind++] = b[j++]; } } while(i<a.length) m[ind++] = a[i++]; while(j<b.length) m[ind++] = b[j++]; return m; } // =================== Fast Print krne ke lie itna mehnat================== public static void print(String str) { out.print(str); } public static void println() { out.println(); } public static void print(int a) { out.print(a); } public static void print(char c) { out.print(c); } public static void print(char c[]) { out.print(Arrays.toString(c)); } public static void print(int a[]) { out.println(Arrays.toString(a)); } public static void print(String a[]) { out.print(Arrays.toString(a)); } public static void print(float a) { out.print(a); } public static void print(double a) { out.print(a); } public static void print(long a[]) { out.print(Arrays.toString(a)); } public static void println(String str) { out.println(str); } public static void println(boolean ap[][]) { for(boolean ele[]:ap) out.println(Arrays.toString(ele)); } public static void println(int a) { out.println(a); } public static void println(char c) { out.println(c); } public static void println(char c[]) { out.println(Arrays.toString(c)); } public static void println(int a[]) { out.println(Arrays.toString(a)); } public static void println(String a[]) { out.println(Arrays.toString(a)); } public static void println(float a) { out.println(a); } public static void println(double a) { out.println(a); } public static void println(long a[]) { out.println(Arrays.toString(a)); } public static void print(int a[][]) { for(int ele[]:a) { out.println(Arrays.toString(ele)); } out.println(); } public static void print(char a[][]) { for(char ele[]:a) { out.println(Arrays.toString(ele)); } } public static void print(long a[][]) { for(long ele[]:a) { out.println(Arrays.toString(ele)); } } public static void print(String a[][]) { for(String ele[]:a) { out.println(Arrays.toString(ele)); } } public static void println(long a) { out.println(a); } public static void println(Long a) { out.println(a); } public static void println(Integer a) { out.println(a); } public static void println(Long a[]) { out.println(Arrays.toString(a)); } public static void println(Integer a[]) { out.println(Arrays.toString(a)); } public static void println(boolean a[]) { out.println(Arrays.toString(a)); } public static void forEach(int a[]) { for(int ele:a) print(ele+" "); println(); } public static void forEach(long a[]) { for(long ele:a) print(ele+" "); println(); } public static void forEach(String a[]) { for(String ele:a) print(ele+" "); println(); } public static void forEach(char a[]) { for(char ele:a) print(ele+" "); println(); } public static void forEach(double a[]) { for(double ele:a) print(ele+" "); println(); } // ================================================== }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
8103fed6cf21fff856a2bf326fe59af8
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main{ // static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } public String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static MyScanner s=new MyScanner(); public static void main(String[] args) { int n=s.nextInt(); for(int u=0;u<n;u++){ int num=s.nextInt(); int k=num/4; if(num%4==0){ } else if(num%4==1){ System.out.print(0+" "); } else if(num%4==2){ System.out.print("4 1 2 12 3 8 "); k--; } else if(num%4==3){ System.out.print(6+" "+1+" "+7+" "); } int start=20; for(int i=0;i<k;i++){ System.out.print(start+" "+(start+3)+" "+(start+1)+" "+(start+2)+" "); start+=4; } System.out.println(); } } } //传送题加一个自己传送自己
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
4f279b2a3d751619cac8b5b120caf041
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class CF_div4_G { static FastReader sc; static void solve() { StringBuilder res = new StringBuilder(); int n = sc.nextInt(); int[] arr = new int[n]; int xor = 0; for (int i = 0; i < n - 3; i++) { arr[i] = i; xor ^= i; } arr[n - 3] = 1 << 28; arr[n - 2] = 1 << 29; arr[n - 1] = xor ^ (1 << 28) ^ (1 << 29); for (int a : arr) res.append(a).append(" "); print(res); } public static void main(String[] args) throws IOException { sc = new FastReader(); int tt = sc.nextInt(); while (tt-- > 0) { solve(); } } static <E> void debug(E a) { System.err.println(a); } static void debug(int... a) { System.err.println(Arrays.toString(a)); } static int maxOf(int... array) { return Arrays.stream(array).max().getAsInt(); } static int minOf(int... array) { return Arrays.stream(array).parallel().reduce(Math::min).getAsInt(); } static <E> void print(E res) { System.out.println(res); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] readLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
fa30ba0cb47cada9ec07742ba7a0c1ab
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class CF_div4_G { static FastReader sc; static void solve() { StringBuilder res = new StringBuilder(); int n = sc.nextInt(); int[] arr = new int[n]; int c = 1; for (int i = 0; i < n; i++) { if (i % 2 == 0) arr[i] = (1 << 29) ^ c; else { arr[i] = (1 << 28) ^ c; c++; } } if (n % 4 == 1) { arr[n - 2] ^= arr[n - 1]; } else if (n % 4 == 2) { arr[n - 1] ^= (1 << 29) | (1 << 23); arr[n - 1] ^= 1 << 23; arr[n - 2] ^= (1 << 28) | (1 << 24); arr[n - 4] ^= 1 << 24; } else if (n % 4 == 3) { arr[n - 3] = 1 << 24; arr[n - 2] = (1 << 24) | (1 << 23); arr[n - 1] = 1 << 23; } for (int a : arr) res.append(a).append(" "); print(res); } public static void main(String[] args) throws IOException { sc = new FastReader(); int tt = sc.nextInt(); while (tt-- > 0) { solve(); } } static <E> void debug(E a) { System.err.println(a); } static void debug(int... a) { System.err.println(Arrays.toString(a)); } static int maxOf(int... array) { return Arrays.stream(array).max().getAsInt(); } static int minOf(int... array) { return Arrays.stream(array).parallel().reduce(Math::min).getAsInt(); } static <E> void print(E res) { System.out.println(res); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] readLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
2ad186a93abbbb440a859238de3a7ed0
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class CF1 { static FastReader sc=new FastReader(); // static long dp[][]; // static boolean v[][][]; // static int mod=998244353;; // static int mod=1000000007; static long oset[]; static int oset_p; static long mod=1000000007; // static int max; // static int bit[]; //static long fact[]; //static HashMap<Long,Long> mp; //static StringBuffer sb=new StringBuffer(""); //static HashMap<Integer,Integer> map; //static List<Integer>list; //static int m; //static StringBuffer sb=new StringBuffer(); // static PriorityQueue<Integer>heap; //static int dp[]; // static boolean cycle; static PrintWriter out=new PrintWriter(System.out); // static int msg[]; static List<int[]>ans; public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""); int ttt=1; ttt =i(); // Queue<int[]>q=new LinkedList<>(); outer :while (ttt-- > 0) { int n=i(); int ans[]=new int[n]; if(n%2==0) { if((n/2)%2==0) { int c=1; for(int i=0;i<n;i++) { if(i%2==0) ans[i]=(1<<30)+c; else ans[i]=c++; } } else { ans[0]=(1<<30)+(1<<29)+1; int c=1; for(int i=1;i<n;i++) { if(i%2==0) ans[i]=(1<<30)+c; else ans[i]=c++; } ans[n-1]+=(1<<30)+(1<<29); } } else { int c=1; for(int i=0;i<n;i++) if(i%2==0) ans[i]=(1<<30)+c; else ans[i]=c++; if(((n-1)/2)%2==0) { ans[n-1]=0; } else { ans[n-1]=(1<<30); } } for(int i=0;i<n;i++) p(ans[i]+" "); pln(""); } out.close(); } public static boolean helper(String t,String str[],int index,int i_index,int len,Integer ind[]) { if(index==len) return true; if(index>len) return false; for(int i=index;i>=i_index;i--) { for(int j=0;j<str.length;j++) { String s=str[j]; if(check(s,t,i,len)) { ans.add(new int[] {ind[j]+1,i+1}); if(helper(t,str,i+s.length(),i+1,len,ind)) return true; ans.remove(ans.size()-1); } } } return false; } public static boolean check(String s,String t,int index,int len) { int p=0; while(p<s.length()&&index<len) { if(s.charAt(p)!=t.charAt(index)) return false; p++; index++; } return p==s.length(); } public static boolean equals(String t,String s,int pt) { int ps=0; for(int i=pt;i<t.length();i++) { if(s.charAt(ps)==t.charAt(i)) { ps++; } else return false; if(ps>=s.length()) return true; } return false; } public static List<Integer> expectedMoney(int N, int M, List<Integer>A, List<Integer>B) { Deque<Integer>dq=new LinkedList<>(); for(int i=N-1;i>0;i--) dq.add(A.get(i)); int sum=0; for(int i=N-1;i>0;i--) sum+=B.get(i); int ans[]=new int[N+1]; int ns=sum; // out.println(sum); for(int i=1;i<=N;i++) { ns+=B.get(A.get(i)); int t=0; // pln(ns+""); while(!dq.isEmpty()&&ns>M) {t=B.get(dq.poll()); ns-= t;} ns-=B.get(A.get(i)); // pln((M-(ns+t))+""); int term=(1+dq.size())*B.get(A.get(i)); if((M-(ns+t))>0) term+=(M-(ns+t)); double k=(double)term/(double)N; String s=Double.toString(k); StringBuffer sb1=new StringBuffer(); StringBuffer sb2=new StringBuffer(); boolean b=false; int c=4; // out.println(s); for(int j=0;j<s.length();j++) { if(s.charAt(j)=='.') { b=true;continue;} if(b) { sb2.append(s.charAt(j)); } else sb1.append(s.charAt(j)); } // out.println(sb1+" "+sb2); for(int j=sb2.length();j<=4;j++) sb2.append(0); StringBuffer sb3=new StringBuffer(); for(int j=0;j<4;j++) sb3.append(sb2.charAt(j)); sb1.append(sb3); String an=sb1.toString(); // out.println(an); int n=Integer.parseInt(an); ans[A.get(i)]=n; dq.addFirst(A.get(i)); ns+=B.get(A.get(i)); } List<Integer>res=new ArrayList<>(); for(int i=1;i<=N;i++) res.add(ans[i]); return res; } static int findPar(int x,int parent[]) { if(parent[x]==x) return x; return parent[x]=findPar(parent[x],parent); } static void union(int u,int v,int parent[],int rank[]) { int x=findPar(u,parent); int y=findPar(v,parent); if(x==y) return; if(rank[x]>rank[y]) { parent[y]=x; } else if(rank[y]>rank[x]) parent[x]=y; else { parent[y]=x; rank[x]++; } } static class Pair implements Comparable<Pair> { int x; int y; // int z; Pair(int x,int y){ this.x=x; this.y=y; // this.z=z; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.x<o.x) return -1; else { if(this.y>o.y) return 1; else if(this.y<o.y) return -1; else return 0; } } public int hashCode() { final int temp = 14; int ans = 1; ans =x*31+y*13; return ans; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (this.getClass() != o.getClass()) { return false; } Pair other = (Pair)o; if (this.x != other.x || this.y!=other.y) { return false; } return true; } // /* FOR TREE MAP PAIR USE */ // public int compareTo(Pair o) { // if (x > o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static ArrayList<Long> gLL() { return new ArrayList<>(); } static ArrayList<Integer> gL() { return new ArrayList<>(); } static StringBuffer gsb() { return new StringBuffer(); } static int find(int A[],int a) { if(A[a]==a) return a; return A[a]=find(A, A[a]); } //static int find(int A[],int a) { // if(A[a]==a) // return a; // return find(A, A[a]); //} //FENWICK TREE static class BIT{ int bit[]; BIT(int n){ bit=new int[n+1]; } int lowbit(int i){ return i&(-i); } int query(int i){ int res=0; while(i>0){ res+=bit[i]; i-=lowbit(i); } return res; } void update(int i,int val){ while(i<bit.length){ bit[i]+=val; i+=lowbit(i); } } } //END static long summation(long A[],int si,int ei) { long ans=0; for(int i=si;i<=ei;i++) ans+=A[i]; return ans; } static void add(long v,Map<Long,Long>mp) { if(!mp.containsKey(v)) { mp.put(v, (long)1); } else { mp.put(v, mp.get(v)+(long)1); } } static void remove(long v,Map<Long,Long>mp) { if(mp.containsKey(v)) { mp.put(v, mp.get(v)-(long)1); if(mp.get(v)==0) mp.remove(v); } } public static int upper(List<Long>A,long k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A.get(mid)<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int upper(long A[],long k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(List<Long>A,long k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A.get(mid)<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } public static int lower(long A[],long k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static void pln(String s) { out.println(s); } static void p(String s) { out.print(s); } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static long[] copy(long A[]) { long B[]=new long[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i<n;i++) { A[i]=sc.nextInt(); } return A; } static long[] inputL(int n) { long A[]=new long[n]; for(int i=0;i<n;i++) { A[i]=sc.nextLong(); } return A; } static String[] inputS(int n) { String A[]=new String[n]; for(int i=0;i<n;i++) { A[i]=sc.next(); } return A; } static long sum(int A[]) { long sum=0; for(int i : A) { sum+=i; } return sum; } static long sum(long A[]) { long sum=0; for(long i : A) { sum+=i; } return sum; } static void reverse(long A[]) { int n=A.length; long B[]=new long[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static void reverse(int A[]) { int n=A.length; int B[]=new int[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static long[] inputL1(int n) { long arr[]=new long[n+1]; for(int i=1;i<=n;i++) arr[i]=l(); return arr; } static int[] input1(int n) { int arr[]=new int[n+1]; for(int i=1;i<=n;i++) arr[i]=i(); return arr; } static void input(int A[],int B[]) { for(int i=0;i<A.length;i++) { A[i]=sc.nextInt(); B[i]=sc.nextInt(); } } static long[][] inputL(int n,int m){ long A[][]=new long[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { A[i][j]=l(); } } return A; } static int[][] input(int n,int m){ int A[][]=new int[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { A[i][j]=i(); } } return A; } static char[][] charinput(int n,int m){ char A[][]=new char[n][m]; for(int i=0;i<n;i++) { String s=s(); for(int j=0;j<m;j++) { A[i][j]=s.charAt(j); } } return A; } static int nextPowerOf2(int n) { if(n==0) return 1; n--; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n++; return n; } static int highestPowerof2(int x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static long highestPowerof2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static char[] cs() { String s=s(); char ch[]=new char[s.length()]; for(int i=0;i<s.length();i++) ch[i]=s.charAt(i); return ch; } static int max(int A[]) { int max=Integer.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static int min(int A[]) { int min=Integer.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long max(long A[]) { long max=Long.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static long min(long A[]) { long min=Long.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long [] prefix(long A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] prefix(int A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] suffix(long A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(int dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(int dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static void fill(long dp[]) { Arrays.fill(dp, -1); } static void fill(long dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(long dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(long dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static int min(int a,int b) { return Math.min(a, b); } static int min(int a,int b,int c) { return Math.min(a, Math.min(b, c)); } static int min(int a,int b,int c,int d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static int max(int a,int b) { return Math.max(a, b); } static int max(int a,int b,int c) { return Math.max(a, Math.max(b, c)); } static int max(int a,int b,int c,int d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long min(long a,long b) { return Math.min(a, b); } static long min(long a,long b,long c) { return Math.min(a, Math.min(b, c)); } static long min(long a,long b,long c,long d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static long max(long a,long b) { return Math.max(a, b); } static long max(long a,long b,long c) { return Math.max(a, Math.max(b, c)); } static long max(long a,long b,long c,long d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long power(long x, long y, long p) { if(y==0) return 1; if(x==0) return 0; long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long power(long x, long y) { if(y==0) return 1; if(x==0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } static void dln(String s) { out.println(s); } static void d(String s) { out.print(s); } static void print(int A[]) { for(int i : A) { out.print(i+" "); } out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+" "); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[]=new Character[s.length()]; for(int i=0;i<s.length();i++) { ch[i]=s.charAt(i); } Arrays.sort(ch); StringBuffer st=new StringBuffer(""); for(int i=0;i<s.length();i++) { st.append(ch[i]); } return st.toString(); } static HashMap<Integer,Long> hash(int A[]){ HashMap<Integer,Long> map=new HashMap<Integer, Long>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+(long)1); } else { map.put(i, (long)1); } } return map; } static HashMap<Long,Long> hash(long A[]){ HashMap<Long,Long> map=new HashMap<Long, Long>(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+(long)1); } else { map.put(i, (long)1); } } return map; } static TreeMap<Integer,Integer> tree(int A[]){ TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap<Long,Integer> tree(long A[]){ TreeMap<Long,Integer> map=new TreeMap<Long, Integer>(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
91432bd85fd0412fd3c77aa248c66e41
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { static class Node { int depth; int num; boolean used; Node left, right; public Node() { this.depth = 0; this.used = false; this.num = 0; this.left = null; this.right = null; } } static int[][] datas = { {0}, {0}, {0}, {2, 1, 3}, {2, 1, 3, 0}, {2, 0, 4, 5, 3}, {4, 1, 2, 12, 3, 8}, {1, 2, 3, 4, 5, 6, 7}, {0}, {8, 2, 3, 7, 4, 0, 5, 6, 9}, {8, 9, 10, 11, 12, 13, 0, 2, 4, 7} }; static int len; static List<Integer> twos; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); twos = new ArrayList<>(); twos.add(8); while (twos.get(twos.size() - 1) < 1_000_000) { twos.add(twos.get(twos.size() - 1) * 2); } StringBuilder sb = new StringBuilder(); for (int tNum = 1; tNum <= t; tNum++) { // List<Integer> answer = new ArrayList<>(); int N = Integer.parseInt(br.readLine()); for (int idx = twos.size() - 1; idx >= 0; idx--) { if (N == twos.get(idx) || N > twos.get(idx) + 2) { N -= twos.get(idx); for(int i = 0; i < twos.get(idx); i++) { // answer.add(i + twos.get(idx) * 2); sb.append(i + twos.get(idx) * 2).append(" "); } } } if (N > 0) { for(int data : datas[N]) { // answer.add(data); sb.append(data).append(" "); } } // sb.append(" "); // int a = 0; // for(int i = 0; i < answer.size(); i += 2) { // a ^= answer.get(i); // } // sb.append(a).append(" "); // a = 0; // for(int i = 1; i < answer.size(); i += 2) { // a ^= answer.get(i); // } // sb.append(a); sb.append("\n"); } System.out.print(sb.toString()); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
b0dc480992a3f591c744048933888025
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; public class cfContest1722 { public static boolean isset(int n, int k) { k += 1; if ((n & (1 << (k - 1))) > 0) { return true; } else { return false; } } static int set(int n, int k) { return ((1 << k) | n); } public static void main(String[] args) { Scanner scan = new Scanner(System.in); StringBuilder sb = new StringBuilder(); int t = scan.nextInt(); k: while (t-- > 0) { int n = scan.nextInt(); ArrayList<Integer> odd = new ArrayList<Integer>(); ArrayList<Integer> even = new ArrayList<Integer>(); int o = 0; int e = 0; for (int i = 1; i <= n / 2 - 1; i++) { odd.add(i); o ^= i; } for (int i = n / 2 + 1; i < n; i++) { even.add(i); e ^= i; } e ^= o; int r = set(0, 29); for (int i = 0; i <= 28; i++) { if (isset(e, i)) { r = set(r, i); } } odd.add(set(0, 29)); even.add(r); int[] res = new int[n]; int l = 0; r = 0; boolean ch = true; for (int i = 0; i < n; i++) { if (ch) { res[i] = even.get(r++); ch = !ch; } else { res[i] = odd.get(l++); ch = !ch; } } for (int i = 0; i < n; i++) { sb.append(res[i] + " "); } int x = 0; int y = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { x ^= res[i]; } else { y ^= res[i]; } } sb.append("\n"); } System.out.println(sb); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
3cbb80ad20571b60b26c74fafa389dad
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class codeforces1722G { public static void main(String[] args) throws Exception { FastScanner in = new FastScanner(); PrintWriter pw = new PrintWriter(System.out); int numCases = in.nextInt(); while (numCases-->0) { int n = in.nextInt(); Vector<Integer> arr = new Vector<>(); if (n%4==3) { arr.add(2); arr.add(1); arr.add(3); n-=3; } else if (n%4==0) { arr.add(2); arr.add(1); arr.add(3); arr.add(0); n-=4; } else if (n%4==1) { arr.add(2); arr.add(0); arr.add(4); arr.add(5); arr.add(3); n-=5; } else { arr.add(4); arr.add(1); arr.add(2); arr.add(12); arr.add(3); arr.add(8); n-=6; } for (int i = 0; i<n;i++) { arr.add(100+i); } for (int i: arr) { pw.print(i+" "); } pw.println(); } pw.close(); } private static class FastScanner { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; private FastScanner() throws IOException { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private short nextShort() throws IOException { short ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do ret = (short) (ret * 10 + c - '0'); while ((c = read()) >= '0' && c <= '9'); if (neg) return (short) -ret; return ret; } private int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do ret = ret * 10 + c - '0'; while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do ret = ret * 10 + c - '0'; while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } private char nextChar() throws IOException { byte c = read(); while (c <= ' ') c = read(); return (char) c; } private String nextString() throws IOException { StringBuilder ret = new StringBuilder(); byte c = read(); while (c <= ' ') c = read(); do { ret.append((char) c); } while ((c = read()) > ' '); return ret.toString(); } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
6360db7efd300f8cbb014b936f985ee8
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; public class p5 { BufferedReader br; StringTokenizer st; BufferedWriter bw; public static void main(String[] args)throws Exception { new p5().run(); } void run()throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); bw=new BufferedWriter(new OutputStreamWriter(System.out)); solve(); } void solve() throws IOException { int t=ni(); while(t-->0) { int n=ni(); int a[]=new int[n]; if(n%4==0) { for(int i=-1;++i<n;) System.out.print(i+" "); } else if(n%4==1) { System.out.print("0 "); int x=4; for(int i=0;++i<n;) System.out.print((x++)+" "); } else if(n%4==3) { System.out.print("2 1 3 "); int x=4; for(int i=-1;++i<n-3;) System.out.print((x++)+" "); } else { System.out.print("3 5 8 6 9 1 "); int x=12; for(int i=-1;++i<n-6;) System.out.print((x++)+" "); } System.out.println(); } } /////////////////////////////////////// FOR INPUT /////////////////////////////////////// int[] nai(int n) { int a[]=new int[n]; for(int i=-1;++i<n;)a[i]=ni(); return a;} Integer[] naI(int n) { Integer a[]=new Integer[n]; for(int i=-1;++i<n;)a[i]=ni(); return a;} long[] nal(int n) { long a[]=new long[n]; for(int i=-1;++i<n;)a[i]=nl(); return a;} char[] nac() {char c[]=nextLine().toCharArray(); return c;} char [][] nmc(int n) {char c[][]=new char[n][]; for(int i=-1;++i<n;)c[i]=nac(); return c;} int[][] nmi(int r, int c) {int a[][]=new int[r][c]; for(int i=-1;++i<r;)a[i]=nai(c); return a;} String next() { while (st == null || !st.hasMoreElements()) { try {st = new StringTokenizer(br.readLine());} catch (IOException e) {e.printStackTrace();} } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } byte nb() { return Byte.parseByte(next()); } short ns() { return Short.parseShort(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try {str = br.readLine();} catch (IOException e) {e.printStackTrace();} return str; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
a0ad24c44771301d77f2c9f04e7cc33c
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; public class Main { // static int [] arr; // static boolean prime[] = new boolean[1000]; // static int l; // static String s; static StringBuilder sb; // static HashSet<L> hs; // static HashSet<Long> hs = new HashSet<Long>(); // static int ans; // static boolean checked []; //static final int mod = 1000000007; // static int[][] dp; // static int[] w ,v; static int n,m; // static int arr[][]; // static long ans; static Scanner sc; static PrintWriter out; //static int n, m, w, t; // static char [] a , b; //static StringBuilder sb; // static int ans; static long[] sum; static long dp[][]; static long ans; static char[] []arr; static ArrayList<Integer> v; public static void main(String[] args) throws IOException, InterruptedException { sc = new Scanner(System.in); out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { n = sc.nextInt(); int [] even = new int[n/2]; int [] odd; if(n%2==1) odd = new int[n/2+1]; else odd = new int[n/2]; for(int i = 0 ; i< n/2 ; i++) { even[i] = i+1; odd[i] = (i+1 | (1<<20)); } int l = even.length; if(odd.length>l) { if(odd.length%2 ==0 ) { odd[l-1] = even[l-1] | (1<<21); odd[l] = (1<<21); } } else if(odd.length%2 ==1) { odd[l-1] = even[l-1] | (1<<22); odd[l-2] = odd[l-2] | (1<<22); } for(int i = 0 ; i < l ; i++) out.print(odd[i] + " " + even[i] + " "); if(n%2==1) out.print(odd[l]); out.println(); // int a = 0; // int b = 0; // for(int x : even) // a = a ^ x; // for(int y : odd) // b = b^y; // out.print("n: " + n + " "); // out.println(a + " " + b); } out.close(); } public static int bs(int target) { int l = 0; int r = v.size()-1; while(l<=r) { int m = (l+r)/2; if(v.get(m) < target) l = m+1; else r = m-1; } return l; } public static void swap(int i , int j ,int [] arr) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } // public static int trace(int idx,int cost){ // if(cost> t || idx == m) // return 0; // int take = v[idx] + solve(idx+1,cost + 3*w*d[idx]); // //int leave = solve(idx+1,t); // if(dp[idx][cost] == take){ // sb.append(d[idx]+" "+v[idx]+"\n"); // return 1 + trace(idx+1,cost+3*w*d[idx]); // } // // return trace(idx+1,cost); // } private static void reverse(long[] arr) { // TODO Auto-generated method stub } // recursive implementation static long arrayLCM(int[] arr, int idx) { // lcm(a,b) = (a*b/gcd(a,b)) if (idx == arr.length - 1) { return arr[idx]; } long a = arr[idx]; long b = arrayLCM(arr, idx + 1); return (a * b / gcd(a, b)); // } static int longestSubarrWthSumDivByK(int arr[], int n, int k) { // unordered map 'um' implemented as // hash table HashMap<Integer, Integer> um = new HashMap<Integer, Integer>(); // 'mod_arr[i]' stores (sum[0..i] % k) int mod_arr[] = new int[n]; int max_len = 0; long curr_sum = 0; // traverse arr[] and build up the // array 'mod_arr[]' for (int i = 0; i < n; i++) { curr_sum += arr[i]; // as the sum can be negative, // taking modulo twice mod_arr[i] = (int) ((curr_sum % k) + k) % k; // if true then sum(0..i) is // divisible by k if (mod_arr[i] == 0) // update 'max' max_len = i + 1; // if value 'mod_arr[i]' not present in 'um' // then store it in 'um' with index of its // first occurrence else if (um.containsKey(mod_arr[i]) == false) um.put(mod_arr[i], i); else // if true, then update 'max' if (max_len < (i - um.get(mod_arr[i]))) max_len = i - um.get(mod_arr[i]); } // return the required length of longest subarray // with sum divisible by 'k' return max_len; } static int longestSubArrayOfSumK(int[] arr, int n, int k) { // HashMap to store (sum, index) tuples HashMap<Integer, Integer> map = new HashMap<>(); int sum = 0, maxLen = 0; // traverse the given array for (int i = 0; i < n; i++) { // accumulate sum sum += arr[i]; // when subarray starts from index '0' if (sum == k) maxLen = i + 1; // make an entry for 'sum' if it is // not present in 'map' if (!map.containsKey(sum)) { map.put(sum, i); } // check if 'sum-k' is present in 'map' // or not if (map.containsKey(sum - k)) { // update maxLength if (maxLen < (i - map.get(sum - k))) maxLen = i - map.get(sum - k); } } return maxLen; } static boolean isPrime(long n) { if (n == 2 || n == 3) return true; if (n <= 1 || n % 2 == 0 || n % 3 == 0) return false; // To check through all numbers of the form 6k ± 1 for (long i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } static long smallestDivisor(long n) { // if divisible by 2 if (n % 2 == 0) return 2; // iterate from 3 to sqrt(n) for (long i = 3; i * i <= n; i += 2) { if (n % i == 0) return i; } return n; } static long nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); } static long fact(int n) { long res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static boolean isSorted(int[] arr) { for (int i = 0; i < arr.length - 1; i++) if (arr[i] > arr[i + 1]) return false; return true; } // static void findsubsequences(String s, String ans){ // if (s.length() == 0) { // if(ans!="") // if(ans.length()!=l) // al.add(Long.parseLong(ans)); // return; // } // // // We add adding 1st character in string // findsubsequences(s.substring(1), ans + s.charAt(0)); // // // Not adding first character of the string // // because the concept of subsequence either // // character will present or not // findsubsequences(s.substring(1), ans); //} static void sieve(int n, boolean[] prime, List<Integer> al) { for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p]) { al.add(p); for (int i = p * p; i <= n; i += p) prime[i] = false; } } } // Print all prime numbers // for(int i = 2; i <= n; i++) // { // if(prime[i] == true) // System.out.print(i + " "); // } public static void reverse(Object[] arr) { int i = 0; int j = arr.length - 1; while (i < j) { Object temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } } } class Pair implements Comparable<Pair> { int a; int b; public Pair(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.a - o.a; } public String toString() { return "( " + this.a + " , " + this.b + " )\n"; } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public int[][] nextInt2DArr(int l, int w) throws IOException { int[][] arr = new int[l][w]; for (int i = 0; i < l; i++) for (int j = 0; j < w; j++) arr[i][j] = Integer.parseInt(next()); return arr; } public Scanner(String file) throws FileNotFoundException { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int length) throws IOException { int[] arr = new int[length]; for (int i = 0; i < length; i++) arr[i] = Integer.parseInt(next()); return arr; } public long[] nextLongArr(int length) throws IOException { long[] arr = new long[length]; for (int i = 0; i < length; i++) arr[i] = Long.parseLong(next()); return arr; } public boolean ready() throws IOException { return br.ready(); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
46ae92dd18b71d25b5d18b60f66fa381
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class HarHarShambhu{ static Scanner in=new Scanner(); static long systemTime; static long mod = 1000000007; //static ArrayList<ArrayList<Integer>> adj; static int seive[]=new int[1000001]; static long C[][]; public static void main(String[] args) throws Exception{ int z=in.readInt(); for(int test=1;test<=z;test++) { //setTime(); solve(); //printTime(); //printMemory(); } } static void solve() { int n=in.readInt(); int a[]=new int[n]; if(n==3) { print(2+" "+1+" "+3); return; } for(int i=0;i<n-n%2;i+=2) { a[i]=i+1; a[i+1]=i+1; } if(n%2==1) { a[n-1]=0; } int half=n/2; if(half%2==0) { for(int i=1;i<n;i+=2) { a[i]|=(1<<29); } } else { for(int i=1;i<n-2;i+=2) { a[i]|=(1<<29); } for(int i=3;i<n;i+=2) { a[i]|=(1<<30); } } // int xor1=0,xor2=0; // for(int i=0;i<n;i++) { // if(i%2==0) { // xor1^=a[i]; // } // else // xor2^=a[i]; // } // print(xor1+" "+xor2); print(a); } static long pow(long n, long m) { if(m==0) return 1; else if(m==1) return n; else { long r=pow(n,m/2); if(m%2==0) return (r*r); else return (r*r*n); } } static long maxsumsub(ArrayList<Long> al) { long max=0; long sum=0; for(int i=0;i<al.size();i++) { sum+=al.get(i); if(sum<0) { sum=0; } max=Math.max(max,sum); } long a[]=al.stream().mapToLong(i -> i).toArray(); return max; } static long abs(long a) { return Math.abs(a); } static void ncr(int n, int k){ C= new long[n + 1][k + 1]; int i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= Math.min(i, k); j++) { if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } } static boolean isPalin(String s) { int i=0,j=s.length()-1; while(i<=j) { if(s.charAt(i)!=s.charAt(j)) { return false; } i++; j--; } return true; } static int knapsack(int W, int wt[],int val[], int n){ int []dp = new int[W + 1]; for (int i = 1; i < n + 1; i++) { for (int w = W; w >= 0; w--) { if (wt[i - 1] <= w) { dp[w] = Math.max(dp[w],dp[w - wt[i - 1]] + val[i - 1]); } } } return dp[W]; } static void seive() { Arrays.fill(seive, 1); seive[0]=0; seive[1]=0; for(int i=2;i*i<1000001;i++) { if(seive[i]==1) { for(int j=i*i;j<1000001;j+=i) { if(seive[j]==1) { seive[j]=0; } } } } } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static int[] nia(int n){ int[] arr= new int[n]; int i=0; while(i<n){ arr[i++]=in.readInt(); } return arr; } static long[] nla(int n){ long[] arr= new long[n]; int i=0; while(i<n){ arr[i++]=in.readLong(); } return arr; } static long[] nla1(int n){ long[] arr= new long[n+1]; int i=1; while(i<=n){ arr[i++]=in.readLong(); } return arr; } static int[] nia1(int n){ int[] arr= new int[n+1]; int i=1; while(i<=n){ arr[i++]=in.readInt(); } return arr; } static Integer[] nIa(int n){ Integer[] arr= new Integer[n]; int i=0; while(i<n){ arr[i++]=in.readInt(); } return arr; } static Long[] nLa(int n){ Long[] arr= new Long[n]; int i=0; while(i<n){ arr[i++]=in.readLong(); } return arr; } static long gcd(long a, long b) { if (b==0) return a; return gcd(b, a%b); } static void no() { System.out.println("NO"); } static void yes() { System.out.println("YES"); } static void print(long i) { System.out.println(i); } static void print(Object o) { System.out.println(o); } static void print(int a[]) { for(int i:a) { System.out.print(i+" "); } System.out.println(); } static void print(long a[]) { for(long i:a) { System.out.print(i+" "); } System.out.println(); } static void print(ArrayList<Long> a) { for(long i:a) { System.out.print(i+" "); } System.out.println(); } static void print(Object a[]) { for(Object i:a) { System.out.print(i+" "); } System.out.println(); } static void setTime() { systemTime = System.currentTimeMillis(); } static void printTime() { System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime)); } static void printMemory() { System.err.println("Memory consumed: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + "kb"); } static class Scanner{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String readString() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } double readDouble() { return Double.parseDouble(readString()); } int readInt() { return Integer.parseInt(readString()); } long readLong() { return Long.parseLong(readString()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
199e3415e58fe085c4eda4026a216b7a
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main { static Scanner sc; static PrintWriter pw; public static void main(String[] args) throws IOException { sc = new Scanner(System.in); pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] res = new int[n]; int a = 0; for (int i = 1; i < n; i += 2) { res[i] = i; a ^= i; } int b = 0; for (int i = 0; i < n - 4; i += 2) { res[i] = i; b ^= i; } int need = a ^ b; int x = (int) 1e9 + 7; if (n % 2 == 0) { res[n - 4] = x; res[n - 2] = x ^ need; } else { res[n - 3] = x; res[n - 1] = x ^ need; } for (int s : res) pw.print(s + " "); pw.println(); } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
94bb8903273386d2f24f81585ec56fd2
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main { static Scanner sc; static PrintWriter pw; public static void main(String[] args) throws IOException { sc = new Scanner(System.in); pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); if (n == 3) { pw.println("2 1 3"); continue; } if (n == 4) { pw.println("2 1 3 0"); continue; } if (n == 5) { pw.println("2 0 4 5 3"); continue; } if (n == 6) { pw.println("4 1 2 12 3 8"); continue; } int[] res = new int[n]; int a = 0; for (int i = 0; i < n; i += 2) { res[i] = i; a ^= i; } int b = 0; for (int i = 1; i < n - 4; i += 2) { res[i] = i; b ^= i; } int need = a ^ b; int x = (int) 1e9 + 7; if (n % 2 == 1) { res[n - 4] = x; res[n - 2] = x ^ need; } else { res[n - 3] = x; res[n - 1] = x ^ need; } for (int s : res) pw.print(s + " "); pw.println(); } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
6779fbc8352141ec2c7e416dd8d7b488
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static int N = 1010; public static void main(String[] args) throws IOException { FastScanner f = new FastScanner(); PrintWriter w = new PrintWriter(System.out); int T = f.nextInt(); while (T-- > 0) { int n = f.nextInt(); int even = 0, odd = 0; long[] a = new long[n + 1]; if ((n - 2) % 4 == 0 || n == 3) { for (int i = 1; i <= n - 2; i++) { a[i] = i; if (i % 2 == 1) odd ^= a[i]; else even ^= a[i]; } int cha = even ^ odd; a[n - 1] = ((1l << 31) - 1); a[n] = ((1l << 31) - 1) ^ cha; } else { for (int i = 1; i <= n - 2; i++) { a[i] = i - 1; if (i % 2 == 1) odd ^= a[i]; else even ^= a[i]; } int cha = even ^ odd; a[n - 1] = ((1l << 31) - 1); a[n] = ((1l << 31) - 1) ^ cha; } for (int i = 1; i <= n; i++) w.print(a[i] + " "); w.println(); } w.flush(); } private static class FastScanner { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; private FastScanner() throws IOException { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private short nextShort() throws IOException { short ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do ret = (short) (ret * 10 + c - '0'); while ((c = read()) >= '0' && c <= '9'); if (neg) return (short) -ret; return ret; } private int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do ret = ret * 10 + c - '0'; while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do ret = ret * 10 + c - '0'; while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } private char nextChar() throws IOException { byte c = read(); while (c <= ' ') c = read(); return (char) c; } private String nextString() throws IOException { StringBuilder ret = new StringBuilder(); byte c = read(); while (c <= ' ') c = read(); do { ret.append((char) c); } while ((c = read()) > ' '); return ret.toString(); } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
fe6e89f2d0af72432b039ba015b692ac
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
/* I am dead inside Do you like NCT, sKz, BTS? 5 4 3 2 1 Moonwalk Imma knock it down like domino Is this what you want? Is this what you want? Let's ttalkbocky about that :() */ import static java.lang.Math.*; import java.util.*; import java.io.*; public class x1722G { static final int INF = Integer.MAX_VALUE/2; public static void main(String[] followthekkathyoninsta) throws Exception { ArrayList<Long> masks = new ArrayList<Long>(); for(int mask=1; mask < 1<<17; mask++) { long val = 0L; for(int b=0; b < 17; b++) if((mask&(1<<b)) > 0) val += 1L<<(b+10); masks.add(val); } BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int T = Integer.parseInt(st.nextToken()); StringBuilder sb = new StringBuilder(); int[][] small = new int[6][]; int[] lol1 = {2, 0, 4, 5, 3}; //5 small[5] = lol1; int[] lol2 = {2, 1, 3, 0}; //1 small[4] = lol2; int[] lol3 = {2, 1, 3}; //1 small[3] = lol3; while(T-->0) { st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); long[] res = new long[N]; int dex = 0; if(N%6 == 1) dex = 1; if(N%6 == 2) { //N >= 8 res[0] = 4; res[1] = 2; res[2] = 1; res[3] = 5; res[4] = 0; res[5] = 6; res[6] = 7; res[7] = 3; dex = 8; } int cmask = 0; while(dex+6 <= N) { long prefix = masks.get(cmask++); res[dex] = 1^prefix; res[dex+1] = 2^prefix; res[dex+2] = 3^prefix; res[dex+3] = 8^prefix; res[dex+4] = 12^prefix; res[dex+5] = 4^prefix; dex += 6; } if(dex < N) { long prefix = masks.get(cmask); int[] suffix = small[N-dex]; for(int i=0; i < suffix.length; i++) res[dex++] = suffix[i]; } for(long x: res) sb.append(x+" "); sb.append("\n"); } System.out.print(sb); } } /* 01 10 11 1 2 3 1000 1100 0100 8 12 4 n=8 4 2 1 5 0 6 7 3 */
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
0605a16f3bf62e9ba910a250fceb2d77
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.Closeable; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.time.Clock; import java.time.LocalDateTime; import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; public class Solution { private void solve() throws IOException { int n = nextInt(); if (n == 3) { println(2, 1, 3); } else if (n == 4) { println(2, 1, 3, 0); } else { int[] a = new int[n]; a[0] = 2; a[1] = 1; a[2] = 3; int[] xr = new int[2]; int[] j = new int[2]; for (int i = 3; i < n; i++) { j[i % 2]++; a[i] = (j[i % 2] << 3) + ((i % 2) << 2); xr[i % 2] ^= (j[i % 2] << 3) + ((i % 2) << 2); } a[0] ^= xr[0]; a[1] ^= xr[1]; xr[0] = 0; xr[1] = 0; for (int i = 0; i < n; i++) { xr[i % 2] ^= a[i]; out.print(a[i] + " "); } out.println(); if (isDebug) { out.flush(); log("xr", xr[0], xr[1]); } } } private static final boolean runNTestsInProd = true; private static final boolean printCaseNumber = false; private static final boolean assertInProd = false; private static final boolean logToFile = false; private static final boolean readFromConsoleInDebug = false; private static final boolean writeToConsoleInDebug = true; private static final boolean testTimer = false; private static Boolean isDebug = null; private BufferedReader in; private StringTokenizer line; private PrintWriter out; public static void main(String[] args) throws Exception { isDebug = Arrays.asList(args).contains("DEBUG_MODE"); if (isDebug) { log = logToFile ? new PrintWriter("logs/j_solution_" + System.currentTimeMillis() + ".log") : new PrintWriter(System.out); clock = Clock.systemDefaultZone(); } new Solution().run(); } private void run() throws Exception { in = new BufferedReader(new InputStreamReader(!isDebug || readFromConsoleInDebug ? System.in : new FileInputStream("input.txt"))); out = !isDebug || writeToConsoleInDebug ? new PrintWriter(System.out) : new PrintWriter("output.txt"); try (Timer totalTimer = new Timer("total")) { int t = runNTestsInProd || isDebug ? nextInt() : 1; for (int i = 0; i < t; i++) { if (printCaseNumber) { out.print("Case #" + (i + 1) + ": "); } if (testTimer) { try (Timer testTimer = new Timer("test #" + (i + 1))) { solve(); } } else { solve(); } if (isDebug) { out.flush(); } } } in.close(); out.flush(); out.close(); } private void println(Object... objects) { boolean isFirst = true; for (Object o : objects) { if (!isFirst) { out.print(" "); } else { isFirst = false; } out.print(o.toString()); } out.println(); } private int[] nextIntArray(int n) throws IOException { return nextIntArray(n, 0); } private int[] nextIntArray(int n, int delta) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt() + delta; } return res; } private long[] nextLongArray(int n) throws IOException { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nextLong(); } return res; } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } private char[] nextTokenChars() throws IOException { return nextToken().toCharArray(); } private String nextToken() throws IOException { while (line == null || !line.hasMoreTokens()) { line = new StringTokenizer(in.readLine()); } return line.nextToken(); } private static void assertPredicate(boolean p) { if ((isDebug || assertInProd) && !p) { throw new RuntimeException(); } } private static void assertPredicate(boolean p, String message) { if ((isDebug || assertInProd) && !p) { throw new RuntimeException(message); } } private static <T> void assertNotEqual(T unexpected, T actual) { if ((isDebug || assertInProd) && Objects.equals(actual, unexpected)) { throw new RuntimeException("assertNotEqual: " + unexpected + " == " + actual); } } private static <T> void assertEqual(T expected, T actual) { if ((isDebug || assertInProd) && !Objects.equals(actual, expected)) { throw new RuntimeException("assertEqual: " + expected + " != " + actual); } } private static PrintWriter log = null; private static Clock clock = null; private static void log(Object... objects) { log(true, objects); } private static void logNoDelimiter(Object... objects) { log(false, objects); } private static void log(boolean printDelimiter, Object[] objects) { if (isDebug) { StringBuilder sb = new StringBuilder(); sb.append(LocalDateTime.now(clock)).append(" - "); boolean isFirst = true; for (Object o : objects) { if (!isFirst && printDelimiter) { sb.append(" "); } else { isFirst = false; } sb.append(o.toString()); } log.println(sb); log.flush(); } } private static class Timer implements Closeable { private final String label; private final long startTime = isDebug ? System.nanoTime() : 0; public Timer(String label) { this.label = label; } @Override public void close() throws IOException { if (isDebug) { long executionTime = System.nanoTime() - startTime; String fraction = Long.toString(executionTime / 1000 % 1_000_000); logNoDelimiter("Timer[", label, "]: ", executionTime / 1_000_000_000, '.', "00000".substring(0, 6 - fraction.length()), fraction, 's'); } } } private static <T> T timer(String label, Supplier<T> f) throws Exception { if (isDebug) { try (Timer timer = new Timer(label)) { return f.get(); } } else { return f.get(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
9aeca60c21a385ea699276955c08f828
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class EvenOddXOR { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t!=0){ solve(br,pr); t--; } pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr) throws IOException{ int n=Integer.parseInt(br.readLine()); int[][] res=new int[n][31]; int[] countEven=new int[31]; int[] countOdd=new int[31]; for(int i=0;i<n;i++){ for(int j=0;j<31;j++){ if((i&(1<<j))!=0){ res[i][j]=1; if(i%2==0){ countEven[j]++; } else{ countOdd[j]++; } } } } res[0][29]=1; res[1][30]=1; res[2][30]=1; res[2][29]=1; for(int j=0;j<31;j++){ if(countEven[j]%2!=countOdd[j]%2){ res[1][j]=1-res[1][j]; } } for(int i=0;i<n;i++){ int num=getNum(res[i]); pr.print(num+" "); } pr.println(); } public static int getNum(int[] bits){ int res=0; for(int i=0;i<31;i++){ if(bits[i]==1){ res|=(1<<i); } } return res; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
1e5b5abf503b7ec9cfe4ed09c2c44c82
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; public class _EvenOddXOR_ { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while (t > 0) { solve(scanner); t--; if(t>1) { System.out.println(""); } } } public static void solve(Scanner scanner) { int n = scanner.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n - 3; i++) { nums[i] = i; } nums[n - 3] = 1 << 30; nums[n - 2] = 1 << 29; for (int i = 0; i < nums.length - 1; i++) { nums[n - 1] ^= nums[i]; } for (int i = 0; i < nums.length; i++) { System.out.print(nums[i]+" "); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
6d25283211ce691e3a167f60c617c302
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Solution{ static Scanner sc; static PrintWriter pw; public static void solve(int n) { long xor1=0; long xor2=0; for(int i=0;i<n-2;i++) { xor1^=i; xor2^=i+1; } if(xor1!=0) { for(int i=0;i<n-2;i++) pw.print(i+" "); long l=1<<31-1; xor1^=l; pw.print(l+" "+xor1); } else { for(int i=1;i<=n-2;i++) pw.print(i+" "); long l=1<<31-1; xor2^=l; pw.print(l+" "+xor2); } pw.println(); } public static void main(String[] args) throws Exception { pw = new PrintWriter(System.out); sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { solve(sc.nextInt()); } pw.flush(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String s) throws Exception { br = new BufferedReader(new FileReader(new File(s))); } public String next() throws Exception { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
75eca8ceb852b06dc0685b533853a6e9
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; public class CodeForces { /*-------------------------------------------EDITING CODE STARTS HERE-------------------------------------------*/ public static void solve(int tCase) throws IOException { int n = sc.nextInt(); List<Integer> left = new ArrayList<>(); List<Integer> right = new ArrayList<>(); if(n==3){ out.println("2 1 3"); return; } if(n%2==1){ left.add(0); n--; } if(n%2==0 && n%4!=0){ left.add(1); left.add(2); left.add(3); right.add(4); right.add(8); right.add(12); n-=6; } int x = 100; for(int i=0;i<n/2;i++){ left.add(x); right.add(x + (1<<20)); x++; } int xorLeft = 0; int xorRight = 0; for (int e : left)xorLeft ^=e; for (int e : right)xorRight ^=e; if(xorLeft!=xorRight){ out.println("wrong for n="+n); } int a = 0; int b = 0; if(left.size() > right.size()){ out.print(left.get(0)+" "); a++; } while (a<left.size() && b<right.size()){ out.print(left.get(a++)+" "+right.get(b++)+" "); } out.println(); } public static void main(String[] args) throws IOException { openIO(); int testCase = 1; testCase = sc.nextInt(); for (int i = 1; i <= testCase; i++) solve(i); closeIO(); } /*-------------------------------------------EDITING CODE ENDS HERE-------------------------------------------*/ /*--------------------------------------HELPER FUNCTIONS STARTS HERE-----------------------------------------*/ public static int mod = (int) 1e9 + 9; // public static int mod = 998244353; public static int inf_int = (int)1e9; public static long inf_long = (long)2e15; public static void _sort(int[] arr, boolean isAscending) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int ele : arr) list.add(ele); Collections.sort(list); if (!isAscending) Collections.reverse(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } public static void _sort(long[] arr, boolean isAscending) { int n = arr.length; List<Long> list = new ArrayList<>(); for (long ele : arr) list.add(ele); Collections.sort(list); if (!isAscending) Collections.reverse(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // time : O(1), space : O(1) public static int _digitCount(long num,int base){ // this will give the # of digits needed for a number num in format : base return (int)(1 + Math.log(num)/Math.log(base)); } // time for pre-computation of factorial and inverse-factorial table : O(nlog(mod)) public static long[] factorial , inverseFact; public static void _ncr_precompute(int n){ factorial = new long[n+1]; inverseFact = new long[n+1]; factorial[0] = inverseFact[0] = 1; for (int i = 1; i <=n; i++) { factorial[i] = (factorial[i - 1] * i) % mod; inverseFact[i] = _modExpo(factorial[i], mod - 2); } } // time of factorial calculation after pre-computation is O(1) public static int _ncr(int n,int r){ if(r > n)return 0; return (int)(factorial[n] * inverseFact[r] % mod * inverseFact[n - r] % mod); } public static int _npr(int n,int r){ if(r > n)return 0; return (int)(factorial[n] * inverseFact[n - r] % mod); } // euclidean algorithm time O(max (loga ,logb)) public static long _gcd(long a, long b) { while (a>0){ long x = a; a = b % a; b = x; } return b; } // lcm(a,b) * gcd(a,b) = a * b public static long _lcm(long a, long b) { return (a / _gcd(a, b)) * b; } // binary exponentiation time O(logn) public static long _modExpo(long x, long n) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans *= x; ans %= mod; n--; } else { x *= x; x %= mod; n >>= 1; } } return ans; } // function to find a/b under modulo mod. time : O(logn) public static long _modInv(long a,long b){ return (a * _modExpo(b,mod-2)) % mod; } //sieve or first divisor time : O(mx * log ( log (mx) ) ) public static int[] _seive(int mx){ int[] firstDivisor = new int[mx+1]; for(int i=0;i<=mx;i++)firstDivisor[i] = i; for(int i=2;i*i<=mx;i++) if(firstDivisor[i] == i) for(int j = i*i;j<=mx;j+=i) if(firstDivisor[j]==j)firstDivisor[j] = i; return firstDivisor; } static class Pair<K, V>{ K ff; V ss; public Pair(K ff, V ss) { this.ff = ff; this.ss = ss; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return ff.equals(pair.ff) && ss.equals(pair.ss); } @Override public int hashCode() { return Objects.hash(ff, ss); } @Override public String toString(){ return ff.toString()+" "+ss.toString(); } } /*--------------------------------------HELPER FUNCTIONS ENDS HERE-----------------------------------------*/ /*-------------------------------------------FAST INPUT STARTS HERE---------------------------------------------*/ static FastestReader sc; static PrintWriter out; private static void openIO() throws IOException { sc = new FastestReader(); out = new PrintWriter(System.out); } public static void closeIO() throws IOException { out.flush(); out.close(); sc.close(); } private static final class FastestReader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; public FastestReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastestReader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() throws IOException { int b; //noinspection StatementWithEmptyBody while ((b = read()) != -1 && isSpaceChar(b)) {} return b; } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); final boolean neg = c == '-'; if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); return neg?-ret:ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); final boolean neg = c == '-'; if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); return neg?-ret:ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); final boolean neg = c == '-'; if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10); return neg?-ret:ret; } public String nextLine() throws IOException { final byte[] buf = new byte[(1<<10)]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } /*---------------------------------------------FAST INPUT ENDS HERE ---------------------------------------------*/ } /** Some points to keep in mind : * 1. don't use Arrays.sort(primitive data type array) * 2. try to make the parameters of a recursive function as less as possible, * more use static variables. * 3. If n = 5000, then O(n^2 logn) need atleast 4 sec to work * 4. dp[2][n] works faster than dp[n][2] * 5. if split wrt 1 char use '\\' before char: .split("\\."); * **/
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
c8ae6fdb825ffa843cc8349819aeaa8e
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; public class Sort { static BufferedReader bf; static PrintWriter out; static Scanner sc; static StringTokenizer st; static long mod = (long)(1e9+7); static long mod2 = 998244353; static long[]fact = new long[200005]; static long[]invFact = new long[200005]; public static void main (String[] args)throws IOException { bf = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); sc = new Scanner(System.in); // solve(); int t = nextInt(); // fact[0] = 1; // invFact[0] = 1; // for(int i = 1;i<=200004;i++){ // fact[i] = (fact[i-1] * i)%mod; // invFact[i] = (binaryExpo(fact[i],mod-2)); // } while(t-->0){ solve(); } } public static void solve() throws IOException{ int n = nextInt(); if(n % 2 == 0){ int[]arr = new int[n]; int j = 1; for(int i = 1;i<n;i+=2){ arr[i] = j++; } j = 1; if((n - (n/2))%2 == 0){ arr[0] = (j | (1<<30)); } else{ arr[0] = j; } j++; arr[0] |= (1<<29); for(int i = 2;i<n;i+=2){ arr[i] = (j | (1 << 30)); if(i == 0 || i == 2){ arr[i] |= (1 << 29); } j++; } int num1 = 0; int num2 = 0; for(int i = 0;i<n;i++){ out.print(arr[i] + " "); if(i %2 == 0)num1 ^= arr[i]; else num2 ^= arr[i]; } out.println(); out.flush(); } else{ int[]arr = new int[n]; int j = 1; for(int i = 1;i<n;i+=2){ arr[i] = j++; } j = 1; if((n - (n/2))%2 == 0){ arr[0] = (1<<30); } for(int i = 2;i<n;i+=2){ arr[i] = (j | (1 << 30)); j++; } for(int i =0 ;i<n;i++){ out.print(arr[i] + " "); } out.println(); out.flush(); } } public static void query(int l,int r){ out.println("? "+l + " "+r); out.flush(); } public static int min(int node,int low,int high,int tlow,int thigh,int[][]tree){ if(low >= tlow&& high <= thigh)return tree[node][0]; if(high < tlow || low > thigh)return Integer.MAX_VALUE; int mid = (low + high)/2; // println(low+" "+high+" "+tlow+" "+thigh); return Math.min(min(node*2,low,mid,tlow,thigh,tree) ,min(node*2+1,mid+1,high,tlow,thigh,tree)); } public static int max(int node,int low,int high,int tlow,int thigh,int[][]tree){ if(low >= tlow && high <= thigh)return tree[node][1]; if(high < tlow || low > thigh)return Integer.MIN_VALUE; int mid = (low + high)/2; return Math.max(max(node*2,low,mid,tlow,thigh,tree) ,max(node*2+1,mid+1,high,tlow,thigh,tree)); } public static long binaryExpo(long base,long expo){ if(expo == 0)return 1; long val = binaryExpo(base,expo/2); val = val * val % mod; if(expo%2 == 1){ val = base * val % mod; } return val; } public static long nCk(int n,int k){ if(k > n)return 0; return fact[n] * invFact[n-k] % mod * invFact[k] % mod; } public static boolean isSorted(int[]arr){ for(int i =1;i<arr.length;i++){ if(arr[i] < arr[i-1]){ return false; } } return true; } //function to find the topological sort of the a DAG public static boolean hasCycle(int[]indegree,List<List<Integer>>list,int n,List<Integer>topo){ Queue<Integer>q = new LinkedList<>(); for(int i =1;i<indegree.length;i++){ if(indegree[i] == 0){ q.add(i); topo.add(i); } } while(!q.isEmpty()){ int cur = q.poll(); List<Integer>l = list.get(cur); for(int i = 0;i<l.size();i++){ indegree[l.get(i)]--; if(indegree[l.get(i)] == 0){ q.add(l.get(i)); topo.add(l.get(i)); } } } if(topo.size() == n)return false; return true; } // function to find the parent of any given node with path compression in DSU public static int find(int val,int[]parent){ if(val == parent[val])return val; return parent[val] = find(parent[val],parent); } // function to connect two components public static void union(int[]rank,int[]parent,int u,int v){ int a = find(u,parent); int b= find(v,parent); if(a == b)return; if(rank[a] == rank[b]){ parent[b] = a; rank[a]++; } else{ if(rank[a] > rank[b]){ parent[b] = a; } else{ parent[a] = b; } } } // public static int findN(int n){ int num = 1; while(num < n){ num *=2; } return num; } // code for input public static void print(String s ){ System.out.print(s); } public static void print(int num ){ System.out.print(num); } public static void print(long num ){ System.out.print(num); } public static void println(String s){ System.out.println(s); } public static void println(int num){ System.out.println(num); } public static void println(long num){ System.out.println(num); } public static void println(){ System.out.println(); } public static int Int(String s){ return Integer.parseInt(s); } public static long Long(String s){ return Long.parseLong(s); } public static String[] nextStringArray()throws IOException{ return bf.readLine().split(" "); } public static String nextString()throws IOException{ return bf.readLine(); } public static long[] nextLongArray(int n)throws IOException{ String[]str = bf.readLine().split(" "); long[]arr = new long[n]; for(int i =0;i<n;i++){ arr[i] = Long.parseLong(str[i]); } return arr; } public static int[][] newIntMatrix(int r,int c)throws IOException{ int[][]arr = new int[r][c]; for(int i =0;i<r;i++){ String[]str = bf.readLine().split(" "); for(int j =0;j<c;j++){ arr[i][j] = Integer.parseInt(str[j]); } } return arr; } public static long[][] newLongMatrix(int r,int c)throws IOException{ long[][]arr = new long[r][c]; for(int i =0;i<r;i++){ String[]str = bf.readLine().split(" "); for(int j =0;j<c;j++){ arr[i][j] = Long.parseLong(str[j]); } } return arr; } static class pair{ int one; int two; pair(int one,int two){ this.one = one ; this.two =two; } } public static long gcd(long a,long b){ if(b == 0)return a; return gcd(b,a%b); } public static long lcm(long a,long b){ return (a*b)/(gcd(a,b)); } public static boolean isPalindrome(String s){ int i = 0; int j = s.length()-1; while(i<=j){ if(s.charAt(i) != s.charAt(j)){ return false; } i++; j--; } return true; } // these functions are to calculate the number of smaller elements after self public static void sort(int[]arr,int l,int r){ if(l < r){ int mid = (l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); smallerNumberAfterSelf(arr, l, mid, r); } } public static void smallerNumberAfterSelf(int[]arr,int l,int mid,int r){ int n1 = mid - l +1; int n2 = r - mid; int []a = new int[n1]; int[]b = new int[n2]; for(int i = 0;i<n1;i++){ a[i] = arr[l+i]; } for(int i =0;i<n2;i++){ b[i] = arr[mid+i+1]; } int i = 0; int j =0; int k = l; while(i<n1 && j < n2){ if(a[i] < b[j]){ arr[k++] = a[i++]; } else{ arr[k++] = b[j++]; } } while(i<n1){ arr[k++] = a[i++]; } while(j<n2){ arr[k++] = b[j++]; } } public static String next(){ while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(bf.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static String nextLine(){ String str = ""; try { str = bf.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // use some math tricks it might help // sometimes just try to think in straightforward plan in A and B problems don't always complecate the questions with thinking too much differently // always use long number to do 10^9+7 modulo // if a problem is related to binary string it could also be related to parenthesis // *****try to use binary search(it is a very beautiful thing it can work in some of the very unexpected problems ) in the question it might work****** // try sorting // try to think in opposite direction of question it might work in your way // if a problem is related to maths try to relate some of the continuous subarray with variables like - > a+b+c+d or a,b,c,d in general // if the question is to much related to left and/or right side of any element in an array then try monotonic stack it could work. // in range query sums try to do binary search it could work // analyse the time complexity of program thoroughly // anylyse the test cases properly // if we divide any number by 2 till it gets 1 then there will be (number - 1) operation required // try to do the opposite operation of what is given in the problem //think about the base cases properly //If a question is related to numbers try prime factorisation or something related to number theory // keep in mind unique strings //you can calculate the number of inversion in O(n log n) // in a matrix you could sometimes think about row and cols indenpendentaly. // Try to think in more constructive(means a way to look through various cases of a problem) way. // observe the problem carefully the answer could be hidden in the given test cases itself. (A, B , C); // when we have equations like (a+b = N) and we have to find the max of (a*b) then the values near to the N/2 must be chosen as (a and b); // give emphasis to the number of occurences of elements it might help. // if a number is even then we can find the pair for each and every number in that range whose bitwise AND is zero. // if each vertex of a graph has exactly one outgoing edge then the graph is called as the functional graph and it has one property that it has exactly one cycle some where in its all the components
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
29575549a20412c5a5487e1437fc0a8b
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.util.spi.CalendarDataProvider; import javax.imageio.metadata.IIOInvalidTreeException; import java.lang.*; import java.sql.Array; // import java.lang.invoke.ConstantBootstraps; // import java.math.BigInteger; // import java.beans.IndexedPropertyChangeEvent; import java.io.*; @SuppressWarnings("unchecked") public class Main implements Runnable { static FastReader in; static PrintWriter out; static int bit(long n) { return (n == 0) ? 0 : (1 + bit(n & (n - 1))); } static void p(Object o) { out.print(o); } static void pn(Object o) { out.println(o); } static void pni(Object o) { out.println(o); out.flush(); } static String n() throws Exception { return in.next(); } static String nln() throws Exception { return in.nextLine(); } static int ni() throws Exception { return Integer.parseInt(in.next()); } static long nl() throws Exception { return Long.parseLong(in.next()); } static double nd() throws Exception { return Double.parseDouble(in.next()); } static class FastReader { static BufferedReader br; static StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception { br = new BufferedReader(new FileReader(s)); } String next() throws Exception { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new Exception(e.toString()); } } return st.nextToken(); } String nextLine() throws Exception { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new Exception(e.toString()); } return str; } } static long power(long a, long b) { if (a == 0L) return 0L; if (b == 0) return 1; long val = power(a, b / 2); val = val * val; if ((b % 2) != 0) val = val * a; return val; } static long power(long a, long b, long mod) { if (a == 0L) return 0L; if (b == 0) return 1; long val = power(a, b / 2L, mod) % mod; val = (val * val) % mod; if ((b % 2) != 0) val = (val * a) % mod; return val; } static ArrayList<Long> prime_factors(long n) { ArrayList<Long> ans = new ArrayList<Long>(); while (n % 2 == 0) { ans.add(2L); n /= 2L; } for (long i = 3; i * i <= n; i++) { while (n % i == 0) { ans.add(i); n /= i; } } if (n > 2) { ans.add(n); } return ans; } static void sort(ArrayList<Long> a) { Collections.sort(a); } static void reverse_sort(ArrayList<Long> a) { Collections.sort(a, Collections.reverseOrder()); } static void swap(long[] a, int i, int j) { long temp = a[i]; a[i] = a[j]; a[j] = temp; } static void swap(List<Long> a, int i, int j) { long temp = a.get(i); a.set(j, a.get(i)); a.set(j, temp); } static void sieve(boolean[] prime) { int n = prime.length - 1; Arrays.fill(prime, true); for (int i = 2; i * i <= n; i++) { if (prime[i]) { for (int j = 2 * i; j <= n; j += i) { prime[j] = false; } } } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static HashMap<Long, Integer> map_prime_factors(long n) { HashMap<Long, Integer> map = new HashMap<>(); while (n % 2 == 0) { map.put(2L, map.getOrDefault(2L, 0) + 1); n /= 2L; } for (long i = 3; i <= Math.sqrt(n); i++) { while (n % i == 0) { map.put(i, map.getOrDefault(i, 0) + 1); n /= i; } } if (n > 2) { map.put(n, map.getOrDefault(n, 0) + 1); } return map; } static List<Long> divisor(long n) { List<Long> ans = new ArrayList<>(); ans.add(1L); long count = 0; for (long i = 2L; i * i <= n; i++) { if (n % i == 0) { if (i == n / i) ans.add(i); else { ans.add(i); ans.add(n / i); } } } return ans; } static void sum_of_divisors(int n) { int[] dp = new int[n + 1]; for (int i = 1; i <= n; i++) { dp[i] += i; for (int j = i + i; j <= n; j += i) { dp[j] += i; } } } static void prime_factorization_using_sieve(int n) { int[] dp = new int[n + 1]; Arrays.fill(dp, Integer.MAX_VALUE); for (int i = 2; i <= n; i++) { dp[i] = Math.min(dp[i], i);// dp[i] stores smallest prime number which divides number i for (int j = 2 * i; j <= n; j++) {// can calculate prime factorization in O(logn) time by dividing // val/=dp[val]; till 1 is obtained dp[j] = Math.min(dp[j], i); } } } /* * ----------------------------------------------------Sorting------------------ * ------------------------------------------------ */ public static void sort(long[] arr, int l, int r) { if (l >= r) return; int mid = (l + r) / 2; sort(arr, l, mid); sort(arr, mid + 1, r); merge(arr, l, mid, r); } public static void sort(int[] arr, int l, int r) { if (l >= r) return; int mid = (l + r) / 2; sort(arr, l, mid); sort(arr, mid + 1, r); merge(arr, l, mid, r); } static void merge(int[] arr, int l, int mid, int r) { int[] left = new int[mid - l + 1]; int[] right = new int[r - mid]; for (int i = l; i <= mid; i++) { left[i - l] = arr[i]; } for (int i = mid + 1; i <= r; i++) { right[i - (mid + 1)] = arr[i]; } int left_start = 0; int right_start = 0; int left_length = mid - l + 1; int right_length = r - mid; int temp = l; while (left_start < left_length && right_start < right_length) { if (left[left_start] < right[right_start]) { arr[temp] = left[left_start++]; } else { arr[temp] = right[right_start++]; } temp++; } while (left_start < left_length) { arr[temp++] = left[left_start++]; } while (right_start < right_length) { arr[temp++] = right[right_start++]; } } static void merge(long[] arr, int l, int mid, int r) { long[] left = new long[mid - l + 1]; long[] right = new long[r - mid]; for (int i = l; i <= mid; i++) { left[i - l] = arr[i]; } for (int i = mid + 1; i <= r; i++) { right[i - (mid + 1)] = arr[i]; } int left_start = 0; int right_start = 0; int left_length = mid - l + 1; int right_length = r - mid; int temp = l; while (left_start < left_length && right_start < right_length) { if (left[left_start] < right[right_start]) { arr[temp] = left[left_start++]; } else { arr[temp] = right[right_start++]; } temp++; } while (left_start < left_length) { arr[temp++] = left[left_start++]; } while (right_start < right_length) { arr[temp++] = right[right_start++]; } } // static int[] smallest_prime_factor; // static int count = 1; // static int[] p = new int[100002]; // static long[] flat_tree = new long[300002]; // static int[] in_time = new int[1000002]; // static int[] out_time = new int[1000002]; // static long[] subtree_gcd = new long[100002]; // static int w = 0; // static boolean poss = true; /* * (a^b^c)%mod * Using fermats Little theorem * x^(mod-1)=1(mod) * so b^c can be written as b^c=x*(mod-1)+y * then (a^(x*(mod-1)+y))%mod=(a^(x*(mod-1))*a^(y))mod * the term (a^(x*(mod-1)))%mod=a^(mod-1)*a^(mod-1) * */ // ---------------------------------------------------Segment_Tree----------------------------------------------------------------// // static class comparator implements Comparator<node> { // public int compare(node a, node b) { // return a.a - b.a > 0 ? 1 : -1; // } // } static class Segment_Tree { private long[] segment_tree; public Segment_Tree(int n) { this.segment_tree = new long[4 * n + 1]; } void build(int index, int left, int right, int[] a) { if (left == right) { segment_tree[index] = a[left]; return; } int mid = (left + right) / 2; build(2 * index + 1, left, mid, a); build(2 * index + 2, mid + 1, right, a); segment_tree[index] = segment_tree[2 * index + 1] + segment_tree[2 * index + 2]; } long query(int index, int left, int right, int l, int r) { if (left > right) return 0; if (left >= l && r >= right) { return segment_tree[index]; } if (l > right || left > r) return 0; int mid = (left + right) / 2; return query(2 * index + 1, left, mid, l, r) + query(2 * index + 2, mid + 1, right, l, r); } void update(int index, int left, int right, int node, int val) { if (left == right) { segment_tree[index] += val; return; } int mid = (left + right) / 2; if (node <= mid) update(2 * index + 1, left, mid, node, val); else update(2 * index + 2, mid + 1, right, node, val); segment_tree[index] = segment_tree[2 * index + 1] + segment_tree[2 * index + 2]; } } static class min_Segment_Tree { private long[] segment_tree; public min_Segment_Tree(int n) { this.segment_tree = new long[4 * n + 1]; } void build(int index, int left, int right, int[] a) { if (left == right) { segment_tree[index] = a[left]; return; } int mid = (left + right) / 2; build(2 * index + 1, left, mid, a); build(2 * index + 2, mid + 1, right, a); segment_tree[index] = Math.min(segment_tree[2 * index + 1], segment_tree[2 * index + 2]); } long query(int index, int left, int right, int l, int r) { if (left > right) return Integer.MAX_VALUE; if (left >= l && r >= right) { return segment_tree[index]; } if (l > right || left > r) return Integer.MAX_VALUE; int mid = (left + right) / 2; return Math.min(query(2 * index + 1, left, mid, l, r), query(2 * index + 2, mid + 1, right, l, r)); } } static class max_Segment_Tree { public long[] segment_tree; public max_Segment_Tree(int n) { this.segment_tree = new long[4 * n + 1]; } void build(int index, int left, int right, int[] a) { // pn(index+" "+left+" "+right); if (left == right) { segment_tree[index] = a[left]; return; } int mid = (left + right) / 2; build(2 * index + 1, left, mid, a); build(2 * index + 2, mid + 1, right, a); segment_tree[index] = Math.max(segment_tree[2 * index + 1], segment_tree[2 * index + 2]); } long query(int index, int left, int right, int l, int r) { if (left >= l && r >= right) { return segment_tree[index]; } if (l > right || left > r) return Integer.MIN_VALUE; int mid = (left + right) / 2; long max = Math.max(query(2 * index + 1, left, mid, l, r), query(2 * index + 2, mid + 1, right, l, r)); // pn(left+" "+right+" "+max); return max; } } // // ------------------------------------------------------ DSU // // --------------------------------------------------------------------// static class dsu { private int[] parent; private int[] rank; private int[] size; public dsu(int n) { this.parent = new int[n + 1]; this.rank = new int[n + 1]; this.size = new int[n + 1]; for (int i = 0; i <= n; i++) { parent[i] = i; rank[i] = 1; size[i] = 1; } } int findParent(int a) { if (parent[a] == a) return a; else return parent[a] = findParent(parent[a]); } void join(int a, int b) { int parent_a = findParent(a); int parent_b = findParent(b); if (parent_a == parent_b) return; if (rank[parent_a] > rank[parent_b]) { parent[parent_b] = parent_a; size[parent_a] += size[parent_b]; } else if (rank[parent_a] < rank[parent_b]) { parent[parent_a] = parent_b; size[parent_b] += size[parent_a]; } else { parent[parent_a] = parent_b; size[parent_b] += size[parent_a]; rank[parent_b]++; } } } // ------------------------------------------------Comparable---------------------------------------------------------------------// public static class rectangle { int x1, x3, y1, y3;// lower left and upper rigth coordinates int x2, y2, x4, y4;// remaining coordinates /* * (x4,y4) (x3,y3) * ____________ * | | * |____________| * * (x1,y1) (x2,y2) */ public rectangle(int x1, int y1, int x3, int y3) { this.x1 = x1; this.y1 = y1; this.x3 = x3; this.y3 = y3; this.x2 = x3; this.y2 = y1; this.x4 = x1; this.y4 = y3; } public long area() { if (x3 < x1 || y3 < y1) return 0; return (long) Math.abs(x1 - x3) * (long) Math.abs(y1 - y3); } } static long intersection(rectangle a, rectangle b) { if (a.x3 < a.x1 || a.y3 < a.y1 || b.x3 < b.x1 || b.y3 < b.y1) return 0; long l1 = ((long) Math.min(a.x3, b.x3) - (long) Math.max(a.x1, b.x1)); long l2 = ((long) Math.min(a.y3, b.y3) - (long) Math.max(a.y1, b.y1)); if (l1 < 0 || l2 < 0) return 0; long area = ((long) Math.min(a.x3, b.x3) - (long) Math.max(a.x1, b.x1)) * ((long) Math.min(a.y3, b.y3) - (long) Math.max(a.y1, b.y1)); if (area < 0) return 0; return area; } static class pair implements Comparable<pair> { int a; int b; int dir; public pair(int a, int b, int dir) { this.a = a; this.b = b; this.dir = dir; } public int compareTo(pair p) { // if (this.b == Integer.MIN_VALUE || p.b == Integer.MIN_VALUE) // return (int) (this.index - p.index); return (int) (this.a - p.a); } } static class pair2 implements Comparable<pair2> { long a; int index; public pair2(long a, int index) { this.a = a; this.index = index; } public int compareTo(pair2 p) { return (int) (this.a - p.a); } } static class node implements Comparable<node> { int l; int r; public node(int l, int r) { this.l = l; this.r = r; } public int compareTo(node a) { if(this.l==a.l){ return this.r-a.r; } return (int) (this.l - a.l); } } static long ans = 0; static int leaf = 0; static boolean poss = true; static long mod = 1000000007L; static int[] dx = { -1, 0, 0, 1 ,-1, -1, 1, 1}; static int[] dy = { 0, -1, 1, 0 ,-1, 1, -1, 1}; static boolean cycle; int count = 0; public static void main(String[] args) throws Exception { // new Thread(null,new Main(), "1", 1 << 26).start(); long start = System.nanoTime(); in = new FastReader(); out = new PrintWriter(System.out, false); int tc = ni(); while (tc-- > 0) { int n=ni(); int[] ans=new int[n]; if(n==3){ pn("2 1 3"); continue; } Set<Integer> set=new HashSet<>(); int count=0; int sum=0; for(int i=0;i<n;i+=2){ sum=sum^count; set.add(count); ans[i]=count; count++; } int xor=0; for(int i=1;i<((n%2)==0?(n-1):(n-2));i+=2){ if(set.contains(xor^count) || set.contains(xor^sum^count)){ count++; i-=2; continue; } set.add(count); ans[i]=count; xor^=count++; } if((n%2)==0){ ans[n-1]=xor^sum; }else{ ans[n-2]=xor^sum; } for(int i=0;i<n;i++)p(ans[i]+" "); pn(""); } long end = System.nanoTime(); // pn((end-start)*1.0/1000000000); out.flush(); out.close(); } static long ncm(long[] fact, long[] fact_inv, int n, int m) { if (n < m) return 0L; long a = fact[n]; long b = fact_inv[n - m]; long c = fact_inv[m]; a = (a * b) % mod; return (a * c) % mod; } public void run() { try { in = new FastReader(); out = new PrintWriter(System.out); int tc = ni(); while (tc-- > 0) { } out.flush(); } catch (Exception e) { } } static int dfs(int i, int j,boolean[][] visited,char[][] c) { visited[i][j] = true; int count=1; for(int k=0;k<8;k++){ int x=i+dx[k]; int y=j+dy[k]; if(inside(x, y, c.length, c[0].length) && !visited[x][y] && c[x][y]=='*'){ count+=dfs(x, y, visited, c); } } return count; } static boolean inside(int i, int j, int n, int m) { if (i >= 0 && j >= 0 && i < n && j < m) return true; return false; } static int binary_search(int[] a, int val) { int l = 0; int r = a.length - 1; int ans = 0; while (l <= r) { int mid = l + (r - l) / 2; if (a[mid] <= val) { ans = mid; l = mid + 1; } else r = mid - 1; } return ans; } static int[] longest_common_prefix(String s) { int m = s.length(); int[] lcs = new int[m]; int len = 0; int i = 1; lcs[0] = 0; while (i < m) { if (s.charAt(i) == s.charAt(len)) { lcs[i++] = ++len; } else { if (len == 0) { lcs[i] = 0; i++; } else len = lcs[len - 1]; } } return lcs; } static void swap(char[] a, char[] b, int i, int j) { char temp = a[i]; a[i] = b[j]; b[j] = temp; } static void factorial(long[] fact, long[] fact_inv, int n, long mod) { fact[0] = 1; for (int i = 1; i < n; i++) { fact[i] = (i * fact[i - 1]) % mod; } for (int i = 0; i < n; i++) { fact_inv[i] = power(fact[i], mod - 2, mod);// (1/x)%m can be calculated by fermat's little theoram which is // (x**(m-2))%m when m is prime } // (a^(b^c))%m is equal to, let res=(b^c)%(m-1) then (a^res)%m // https://www.geeksforgeeks.org/find-power-power-mod-prime/?ref=rp } static void find(int i, int n, int[] row, int[] col, int[] d1, int[] d2) { if (i >= n) { ans++; return; } for (int j = 0; j < n; j++) { if (col[j] == 0 && d1[i - j + n - 1] == 0 && d2[i + j] == 0) { col[j] = 1; d1[i - j + n - 1] = 1; d2[i + j] = 1; find(i + 1, n, row, col, d1, d2); col[j] = 0; d1[i - j + n - 1] = 0; d2[i + j] = 0; } } } static int answer(int l, int r, int[][] dp) { if (l > r) return 0; if (l == r) { dp[l][r] = 1; return 1; } if (dp[l][r] != -1) return dp[l][r]; int val = Integer.MIN_VALUE; int mid = l + (r - l) / 2; val = 1 + Math.max(answer(l, mid - 1, dp), answer(mid + 1, r, dp)); return dp[l][r] = val; } // static long find(String s, int i, int n, long[] dp) { // pn(i); // if (i >= n) // return 1L; // if (s.charAt(i) == '0') // return 0; // if (i == n - 1) // return 1L; // if (dp[i] != -1) // return dp[i]; // if (s.substring(i, i + 2).equals("10") || s.substring(i, i + 2).equals("20")) // { // return dp[i] = (find(s, i + 2, n, dp)) % mod; // } // if ((s.charAt(i) == '1' || (s.charAt(i) == '2' && s.charAt(i + 1) - '0' <= // 6)) // && ((i + 2 < n ? (s.charAt(i + 2) != '0' ? true : false) : (i + 2 == n ? true // : false)))) { // return dp[i] = (find(s, i + 1, n, dp) + find(s, i + 2, n, dp)) % mod; // } else // return dp[i] = (find(s, i + 1, n, dp)) % mod; static void print(int[] a) { for (int i = 0; i < a.length; i++) p(a[i] + " "); pn(""); } static long count(long n) { long count = 0; while (n != 0) { count += n % 10; n /= 10; } return count; } static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } static int LcsOfPrefix(String a, String b) { int i = 0; int j = 0; int count = 0; while (i < a.length() && j < b.length()) { if (a.charAt(i) == b.charAt(j)) { j++; count++; } i++; } return a.length() + b.length() - 2 * count; } static void reverse(int[] a, int n) { for (int i = 0; i < n / 2; i++) { int temp = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = temp; } } static char get_char(int a) { return (char) (a + 'A'); } static int find1(int[] a, int val) { int ans = -1; int l = 0; int r = a.length - 1; while (l <= r) { int mid = l + (r - l) / 2; if (a[mid] <= val) { l = mid + 1; ans = mid; } else r = mid - 1; } return ans; } static int find2(int[] a, int val) { int l = 0; int r = a.length - 1; int ans = -1; while (l <= r) { int mid = l + (r - l) / 2; if (a[mid] <= val) { ans = mid; l = mid + 1; } else r = mid - 1; } return ans; } // static void dfs(List<List<Integer>> arr, int node, int parent, long[] val) { // p[node] = parent; // in_time[node] = count; // flat_tree[count] = val[node]; // subtree_gcd[node] = val[node]; // count++; // for (int adj : arr.get(node)) { // if (adj == parent) // continue; // dfs(arr, adj, node, val); // subtree_gcd[node] = gcd(subtree_gcd[adj], subtree_gcd[node]); // } // out_time[node] = count; // flat_tree[count] = val[node]; // count++; // } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
720a7979c565df06a9d7f2407291fcd2
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
//package contest.CodeforcesRound817; import java.io.*; import java.util.*; public class G1712 { InputStream is; FastWriter out; String INPUT = ""; //提交时注意需要注释掉首行package //尽量用对象Arrays.sort(new Long[]{}) //int 最大值2**31-1,2147483647; //尽量使用long类型,避免int计算的数据溢出 //String尽量不要用+号来,可能会出现TLE,推荐用StringBuffer //注意对象类型Long,Integer相等使用equals代替== !!! //乘法可能溢出 void solve() { int t = ni(); for (; t > 0; t--) go(); } void go() { int n = ni(); if (n == 3) { out.println(new long[]{1, 2, 3}); return; } long p = 1; for (int i = 0; i < 30; i++) { p = p * 2; } // out.println(p); long[] ans = new long[n]; for (int i = 0; i < n / 2; i++) { ans[2 * i] = i + 1; ans[2 * i + 1] = p + i + 1; } if (n % 2 == 1) { ans[n - 1] = 0; } int cnt = n / 2; if (cnt % 2 == 1) { ans[1] = ans[0] + p / 2; ans[3] = ans[2] + (p ^ p / 2); } long even = ans[0], odd = ans[1]; for (int i = 2; i < n; i += 2) { even = even ^ ans[i]; } for (int i = 3; i < n; i += 2) { odd = odd ^ ans[i]; } // out.println(new long[]{even, odd}); out.println(ans); } void run() throws Exception { is = System.in; out = new FastWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); //debug log //tr(System.currentTimeMillis() - s + "ms"); } public static void main(String[] args) throws Exception { new G1712().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private Integer[] na(int n) { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private Long[] nal(int n) { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private Integer[][] nmi(int n, int m) { Integer[][] map = new Integer[n][]; for (int i = 0; i < n; i++) map[i] = na(m); return map; } private int ni() { return (int) nl(); } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } write((long) x).write("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(Long... xs) { boolean first = true; for (Long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(Long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(Long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } public void trnz(int... o) { for (int i = 0; i < o.length; i++) if (o[i] != 0) System.out.print(i + ":" + o[i] + " "); System.out.println(); } // print ids which are 1 public void trt(long... o) { Queue<Integer> stands = new ArrayDeque<>(); for (int i = 0; i < o.length; i++) { for (long x = o[i]; x != 0; x &= x - 1) stands.add(i << 6 | Long.numberOfTrailingZeros(x)); } System.out.println(stands); } public void tf(boolean... r) { for (boolean x : r) System.out.print(x ? '#' : '.'); System.out.println(); } public void tf(boolean[]... b) { for (boolean[] r : b) { for (boolean x : r) System.out.print(x ? '#' : '.'); System.out.println(); } System.out.println(); } public void tf(long[]... b) { if (INPUT.length() != 0) { for (long[] r : b) { for (long x : r) { for (int i = 0; i < 64; i++) { System.out.print(x << ~i < 0 ? '#' : '.'); } } System.out.println(); } System.out.println(); } } public void tf(long... b) { if (INPUT.length() != 0) { for (long x : b) { for (int i = 0; i < 64; i++) { System.out.print(x << ~i < 0 ? '#' : '.'); } } System.out.println(); } } private void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
1b6da7211c343d0192d59ab128f32c34
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] ans = new int[n]; if (n % 4 == 0) { for (int i = 0; i < ans.length; i += 2) { ans[i] = i / 2; ans[i + 1] = i / 2 + (1 << 28); } } else if (n % 4 == 1) { for (int i = 0; i < ans.length - 1; i += 2) { ans[i] = i / 2 + 4; ans[i + 1] = i / 2 + (1 << 28); } } else if (n % 4 == 2) { int[] arr = { 4, 1, 2, 12, 3, 8 }; for (int i = 0; i < ans.length - 6; i += 2) { ans[i] = i / 2 + 16; ans[i + 1] = i / 2 + (1 << 28); } for (int i = ans.length - 6; i < ans.length; i++) { ans[i] = arr[i - ans.length + 6]; } } else { int p = (1 << 28); for (int i = 0; i < ans.length - 1; i += 2) { ans[i] = p++; ans[i + 1] = i / 2 + 1; } ans[n - 1] = p; } for (int i = 0; i < ans.length; i++) { pw.print(ans[i] + " "); } pw.println(); } pw.close(); } // 0 1 10 11 100 101 110 111 1000 // public static class pair implements Comparable<pair> { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } public static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return Long.compare(this.z, other.z); } return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(String string) throws FileNotFoundException { br = new BufferedReader(new FileReader(string)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
99919914d4e1acc869f603016e1a75e0
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class A { static Scanner sc; static PrintWriter pw; public static void main(String[] args) throws Exception { pw = new PrintWriter(System.out); sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); if (n % 2 == 1) { int xor1 = 0, xor2 = 0; for (int i = 0; i < n - 3; i += 2) { xor1 ^= i; xor2 ^= i + 1; pw.print(i + " " + (i + 1) + " "); } pw.print(1l << 29); pw.print(" "); pw.print((1l << 29) ^ xor1 ^ xor2 ^ (1l << 28)); pw.print(" "); pw.print(1l<<28); } else if (n % 4 == 0) { int xor1 = 0, xor2 = 0; for (int i = 0; i < n - 3; i += 2) { xor1 ^= i; xor2 ^= i + 1; pw.print(i + " " + (i + 1) + " "); } pw.print(n - 2 + " " + (n - 1)); } else { int xor1 = 0, xor2 = 0; for (int i = 0; i < n - 4; i += 2) { xor1 ^= i; xor2 ^= i + 1; pw.print(i + " " + (i + 1) + " "); } pw.print(1l << 29); pw.print(" "); pw.print((1l << 29) ^ xor1 ^ xor2 ^ (1l << 28) ^ (1l << 27)); pw.print(" "); pw.print(1 << 28); pw.print(" "); pw.print(1l << 27); } pw.println(); } pw.flush(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String s) throws Exception { br = new BufferedReader(new FileReader(new File(s))); } public String next() throws Exception { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
7766f3cc6ade0262e88e09eef8339af4
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.PrintStream; import java.util.Scanner; public class G { public static final Scanner in = new Scanner(System.in); public static final PrintStream out = System.out; public static void main(String[] args) { int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int xors = 0; int[] answer = new int[n]; for (int i = 0; i < n - 1; i++) { answer[i] = i; xors ^= i; } answer[n - 1] = xors | (1 << 30); if (answer[n - 2] != xors) { answer[n - 2] |= (1 << 30); } else { answer[n - 3] |= (1 << 30); } for (int i = 0; i < n; i++) { out.print(answer[i] + " "); } out.println(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
d45bd091226120b4964b3e952e218b23
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.util.concurrent.ConcurrentHashMap; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { static final int INF=Integer.MAX_VALUE; static final long LINF=Long.MAX_VALUE; static FastReader in; static { try { in = new FastReader(); } catch (FileNotFoundException e) { e.printStackTrace(); } } static PrintWriter out = new PrintWriter(System.out); static int n; public static void main(String[] args) throws FileNotFoundException { int t=in.nextInt(); while(t-->0){ n=in.nextInt(); solve(); } out.flush(); in.close(); } static private void solve(){ int evenxor=0; int oddxor=0; for(int i=1;i<=n-2;i++){ if((i&1)!=0){ oddxor^=i; }else{ evenxor^=i; } } if(evenxor!=oddxor){ for(int i=1;i<=n-2;i++){ out.print(i+" "); } out.print(((1<<30)|evenxor)+" "+((1<<30)|oddxor)); }else{ int temp=(1<<21); for(int i=1;i<=n-3;i++){ if((i&1)!=0){ oddxor^=i; }else{ evenxor^=i; } out.print(i+" "); } out.print(temp+" "); if((n-3)%2==0){ oddxor^=temp; }else{ evenxor^=temp; } out.print(((1<<30)|evenxor)+" "+((1<<30)|oddxor)); } out.println(); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws FileNotFoundException { //br = new BufferedReader(new InputStreamReader(new FileInputStream("/home/chaitanya/gitrepo/ds/src/main/resources/ts2_input.txt"))); br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } void close(){ try { br.close(); } catch (IOException e) { e.printStackTrace(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
22da488925a89180066494dd6249ca9d
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; import java.util.List; import java.util.LinkedList; public class G1722{ public static void main(String[] args){ int maxNum = 1; for(int i=0; i<30; i++){ maxNum = maxNum<<1; } //System.out.println(maxNum); Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0; i<t; i++){ int n = sc.nextInt(); LinkedList<Integer> res = new LinkedList<>(); int flag = 0; for(int j=0; j<n-2; j++){ res.add(j); flag ^= j; } if(flag!=0){ res.add(maxNum); flag ^= maxNum; res.add(flag); }else{ res.removeFirst(); res.add(n-2); flag ^= 0; flag ^= n-2; res.add(maxNum); flag ^= maxNum; res.add(flag); } printRes(res); } } static void printRes(List<Integer> res){ StringBuilder sb = new StringBuilder(); for(int num: res){ sb.append(num); sb.append(" "); } System.out.println(sb.toString()); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
162a0a4cde7f44e3f1214154f0a99623
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; public class G1722 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int N = in.nextInt(); int[] A = new int[N]; int xor = 0; for (int n=0; n<N-2; n++) { A[n] = n; xor ^= n; } int last = N-3; if (xor == 0) { xor ^= last; A[N-3] = ++last; xor ^= last; } int next = last+1; while ((xor^next) <= last) { next++; } A[N-2] = next; A[N-1] = xor^next; StringBuilder out = new StringBuilder(); for (int a : A) { out.append(a).append(' '); } System.out.println(out); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
826ce7c72c04d795fa5588b71d26b34c
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; // res.append("Case #"+(p+1)+": "+hh+" \n"); ////*************************************************************************** /* public class E_Gardener_and_Tree implements Runnable{ public static void main(String[] args) throws Exception { new Thread(null, new E_Gardener_and_Tree(), "E_Gardener_and_Tree", 1<<28).start(); } public void run(){ WRITE YOUR CODE HERE!!!! JUST WRITE EVERYTHING HERE WHICH YOU WRITE IN MAIN!!! } } */ /////************************************************************************** public class sss{ public static void main(String[] args) { FastScanner s= new FastScanner(); PrintWriter out=new PrintWriter(System.out); //end of program //out.println(answer); //out.close(); StringBuilder res = new StringBuilder(); int t=s.nextInt(); int p=0; while(p<t){ int n=s.nextInt(); long array[]= new long[n]; ArrayList<Integer> list2 = new ArrayList<>(); for(int i=0;i<n;i++){ list2.add(i); } ArrayList<ArrayList<Integer>> list = new ArrayList<>(); list.add(list2); for(int i=0;i<31;i++){ ArrayList<ArrayList<Integer>> list3 = new ArrayList<>(); int count=0; for(int j=0;j<list.size();j++){ ArrayList<Integer> one = new ArrayList<>(); ArrayList<Integer> zero= new ArrayList<>(); ArrayList<Integer> obj = list.get(j); int even=0; ArrayList<Integer> evenlist = new ArrayList<>(); ArrayList<Integer> oddlist = new ArrayList<>(); int odd=0; for(int k=0;k<obj.size();k++){ int num=obj.get(k); if(num%2==0){ even++; evenlist.add(num); } else{ odd++; oddlist.add(num); } } if(even==0){ if(odd>2){ int half=odd/2; if(half%2!=0){ half++; } for(int k=0;k<half;k++){ one.add(oddlist.get(k)); int yo=oddlist.get(k); long hh=1L<<i; array[yo]=array[yo]|hh; } count++; for(int k=half;k<odd;k++){ zero.add(oddlist.get(k)); } } } else if(odd==0){ if(even>2){ int half=even/2; if(half%2!=0){ half++; } for(int k=0;k<half;k++){ one.add(evenlist.get(k)); int yo=evenlist.get(k); long hh=1L<<i; array[yo]=array[yo]|hh; } count++; for(int k=half;k<even;k++){ zero.add(evenlist.get(k)); } } } else{ if(even==1 && odd==1){ list3.add(obj); } else{ count++; int half1=even/2; int half2=odd/2; int min=Math.min(half1,half2); int max=Math.max(half1,half2); if((min%2)!=(max%2)){ min++; } // out.println("half1 "+half1); // out.println("half2 "+half2); if(max==half1){ //max is from even for(int k=0;k<max;k++){ int yo=evenlist.get(k); long hh=1L<<i; array[yo]=array[yo]|hh; one.add(yo); } for(int k=max;k<even;k++){ zero.add(evenlist.get(k)); } for(int k=0;k<min;k++){ int yo=oddlist.get(k); long hh=1L<<i; array[yo]=array[yo]|hh; one.add(yo); } for(int k=min;k<odd;k++){ zero.add(oddlist.get(k)); } } else{ //max==half2 //max is from odd for(int k=0;k<max;k++){ int yo=oddlist.get(k); long hh=1L<<i; array[yo]=array[yo]|hh; one.add(yo); } for(int k=max;k<odd;k++){ zero.add(oddlist.get(k)); } for(int k=0;k<min;k++){ int yo=evenlist.get(k); long hh=1L<<i; array[yo]=array[yo]|hh; one.add(yo); } for(int k=min;k<even;k++){ zero.add(evenlist.get(k)); } } } } if(one.size()>1){ list3.add(one); } if(zero.size()>1){ list3.add(zero); } } if(count==0){ int even=0; int odd=0; long hh=1L<<i; int first=-1; int second=-1; // out.println("here "); for(int j=0;j<list.size();j++){ ArrayList<Integer> obj =list.get(j); int num1=obj.get(0); int num2=obj.get(1); // out.println("num1 "+num1); // out.println("num2 "+num2); if(j==0){ first=num1; second=num2; continue; } array[num2]=array[num2]|hh; if(num2%2==0){ even++; } else{ odd++; } } if((even%2)!=(odd%2)){ array[first]=array[first]|hh; } else{ long hh2=1L<<(i+1); int third=-1; if(first!=0 && second!=0){ third=0; } else if(first!=1 && second!=1){ third=1; } else{ third=2; } array[first]=array[first]|hh2; array[third]=array[third]|hh2; } break; } list=list3; } for(int i=0;i<n;i++){ res.append(array[i]+" "); } long alpha=0; long beta=0; for(int i=0;i<n;i++){ if(i%2==0){ alpha=alpha^array[i]; } else{ beta=beta^array[i]; } } //out.println("alpha "+alpha); // out.println("beta "+beta); res.append("\n"); p++;} out.println(res); out.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } static long modpower(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // SIMPLE POWER FUNCTION=> static long power(long x, long y) { long res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = res * x; // y must be even now y = y >> 1; // y = y/2 x = x * x; // Change x to x^2 } return res; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
8bb3ed3ab5f1d4e2f88bc3c11a60befd
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
//package com.example.lib; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.PriorityQueue; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; public class Algorithm { static int ans =0; static boolean found= false; public static void main(String[] rgs) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); // BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\Users\\USER\\AndroidStudioProjects\\MyApplication\\lib\\src\\main\\java\\com\\example\\lib\\inpu")); StringBuilder stringBuilder = new StringBuilder(); int mod =1_000_000_007; long t = Long.parseLong(bufferedReader.readLine()); for (int i = 0; i < t; i++) { int size =Integer.parseInt( bufferedReader.readLine()); int [] ans = new int[size]; if (size == 3){ int [] x={2,1,3}; for (int j = 0; j < 3; j++) { stringBuilder.append(x[j]).append(" "); } stringBuilder.append("\n"); continue; } int even =0; int odd=1; int mask = Integer.parseInt("1111111111111111111111111111111",2); // System.out.println(mask); if(size% 4==0 || size%4==1){ for (int j = 13; j <13 +(size/2) ; j++) { if(j%2==0){ ans[even]=j; ans[even+2]=(~j)&mask; even+=4; }else{ ans[odd]=j; ans[odd+2]=(~j)&mask; odd+=4; } } }else{ for (int j = 13; j <13 +((size-6)/2) ; j++) { if(j%2==0){ ans[even]=j; ans[even+2]=(~j)&mask; even+=4; }else{ ans[odd]=j; ans[odd+2]=(~j)&mask; odd+=4; } } int start = Math.min(even,odd); int []y= {4,1,2,12,3,8}; for (int j = start; j <start+6 ; j++) { ans[j]= y[j-start]; } } for (int j = 0; j < ans.length; j++) { stringBuilder.append(ans[j]).append(" "); } stringBuilder.append("\n"); } System.out.println(stringBuilder); } private static int getParent(int pos, int[] parents) { int orig=pos; while(parents[pos]!=pos){ pos= parents[pos]; } while (parents[orig]!=pos){ orig= parents[orig]; parents[orig]=pos; } return pos; } static int []addcol= {-1,0,1,0}; static int []addrow= {0,1,0,-1}; static int size =0; private static int dfs(int row, int col, int[][] grid, boolean[][] visited) { // if() if(visited[row][col])return 0; visited[row][col]=true; int siz=1; int cur= grid[row][col]; for (int i = 0; i < 4; i++) { int anding = 1 <<i; int andrem= anding & cur; if(andrem == 0){ siz+=dfs(row+addrow[i],col+addcol[i],grid,visited); } } return siz; } private static boolean palpossible(int bigsum, int mid, int k, int lengthofletter) { if(mid%2==0){ return bigsum>=(mid/2)*k; }else { int temp= (mid/2)*k; return bigsum>=temp && lengthofletter - (temp*2) >=k; } } private static void gen(List<Integer> powetrs, List<Integer> comb, int sumSoFar, int pos) { if(pos==powetrs.size()){ if(sumSoFar==0)return; comb.add(sumSoFar); return; } gen(powetrs,comb,sumSoFar+powetrs.get(pos),pos+1); gen(powetrs,comb,sumSoFar,pos+1); } private static int gcd(int fir, int sec) { if(fir==0)return sec; if(fir>sec)return gcd(fir%sec,sec); return gcd(sec%fir,fir); } // private static void rec(List<Integer> primes, int position, int productsofar, HashSet<Integer> divisors) { // if(position==primes.size()){ // divisors.add(productsofar); // return; // } // rec(primes,position+1,productsofar*primes.get(position),divisors); // rec(primes,position+1,productsofar,divisors); // // } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
032254a2168944d61464d8fd23f7802f
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); int xor = 0; for (int j = 1; j < n - 2; j++) { xor ^= j; System.out.print(j + " "); } if (xor == 0) { System.out.print(n - 2 + " "); xor ^= n - 2; } else { System.out.print(0 + " "); } System.out.print( (1 << 30) + " "); System.out.println(xor ^ (1 << 30)); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
9be7ea8cf197fc102f4f2a0037e7378d
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; public class G { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int xor = 0; int[] ans = new int[n]; ans[n-2] = (1<<30); ans[n-3] = (1<<29); xor^=ans[n-2]; xor^=ans[n-3]; for (int i = 0; i < n-3; i++) { ans[i] = i; xor^=ans[i]; } ans[n-1] = xor; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(ans[i]).append(" "); } System.out.println(sb); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
2766dcd2dc78d7e9967a59984e6eec01
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.security.cert.X509CRL; import java.util.*; import java.lang.*; import java.util.stream.Collector; import java.util.stream.Collectors; @SuppressWarnings("unused") public class Main { static InputStream is; static PrintWriter out; //static String INPUT = "in.txt"; static String INPUT = ""; static String OUTPUT = ""; //global const //private final static long BASE = 998244353L; private final static int ALPHABET = (int)('z') - (int)('a') + 1; private final static long BASE = 1000000007l; private final static int INF_I = 1000000000; private final static long INF_L = 10000000000000000l; private final static int MAXN = 200100; private final static int MAXK = 31; private final static int[] DX = {-1,0,1,0}; private final static int[] DY = {0,1,0,-1}; static void solve() { //int ntest = 1; int ntest = readInt(); for (int test=0;test<ntest;test++) { int N = readInt(); int[] ans = new int[N]; int last = 0; for (int i=1; i<N; i++) { ans[i-1] = i; last ^= i; } ans[N-1] = last; int pos = 0; for (int i=0; i<N; i++) if (ans[i] == ans[N-1]) { pos = i; break; } if (pos!=N-1) { ans[pos] ^= (1<<30); int next = pos + 1; if (next == N-1) next = pos - 1; ans[next] ^= (1<<30); } for (int i=0; i<N; i++) out.print(ans[i] + " "); out.println(); } } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); if (INPUT=="") { is = System.in; } else { File file = new File(INPUT); is = new FileInputStream(file); } if (OUTPUT == "") out = new PrintWriter(System.out); else out = new PrintWriter(OUTPUT); solve(); out.flush(); long G = System.currentTimeMillis(); } private static class MultiSet<T extends Comparable<T>> { private TreeSet<T> set; private Map<T, Integer> count; public MultiSet() { this.set = new TreeSet<>(); this.count = new HashMap<>(); } public void add(T x) { this.set.add(x); int o = this.count.getOrDefault(x, 0); this.count.put(x, o+1); } public void remove(T x) { int o = this.count.getOrDefault(x, 0); if (o==0) return; this.count.put(x, o-1); if (o==1) this.set.remove(x); } public void removeAll(T x) { int o = this.count.getOrDefault(x, 0); if (o==0) return; this.count.put(x, 0); this.set.remove(x); } public T first() { return this.set.first(); } public T last() { return this.set.last(); } public int getCount(T x) { return this.count.getOrDefault(x, 0); } public int size() { int res = 0; for (T x: this.set) res += this.count.get(x); return res; } } private static class Point<T extends Number & Comparable<T>> implements Comparable<Point<T>> { private T x; private T y; public Point(T x, T y) { this.x = x; this.y = y; } public T getX() {return x;} public T getY() {return y;} @Override public int compareTo(Point<T> o) { int cmp = x.compareTo(o.getX()); if (cmp==0) return y.compareTo(o.getY()); return cmp; } } private static class ClassComparator<T extends Comparable<T>> implements Comparator<T> { public ClassComparator() {} @Override public int compare(T a, T b) { return a.compareTo(b); } } private static class ListComparator<T extends Comparable<T>> implements Comparator<List<T>> { public ListComparator() {} @Override public int compare(List<T> o1, List<T> o2) { for (int i = 0; i < Math.min(o1.size(), o2.size()); i++) { int c = o1.get(i).compareTo(o2.get(i)); if (c != 0) { return c; } } return Integer.compare(o1.size(), o2.size()); } } private static boolean eof() { if(lenbuf == -1)return true; int lptr = ptrbuf; while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false; try { is.mark(1000); while(true){ int b = is.read(); if(b == -1){ is.reset(); return true; }else if(!isSpaceChar(b)){ is.reset(); return false; } } } catch (IOException e) { return true; } } private static byte[] inbuf = new byte[1024]; static int lenbuf = 0, ptrbuf = 0; private static int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } // private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); } private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private static double readDouble() { return Double.parseDouble(readString()); } private static char readChar() { return (char)skip(); } private static String readString() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private static char[] readChar(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private static char[][] readTable(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = readChar(m); return map; } private static int[] readIntArray(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = readInt(); return a; } private static long[] readLongArray(int n) { long[] a = new long[n]; for (int i=0;i<n;i++) a[i] = readLong(); return a; } private static int readInt() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static long readLong() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
907aa57374eae0217d71666a5003a294
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
//package kg.my_algorithms.Codeforces; import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader fr = new FastReader(); StringBuilder sb = new StringBuilder(); int testCases = fr.nextInt(); for(int test=1;test<=testCases;test++){ int n = fr.nextInt(); int x = (1<<29)^(1<<30); for(int i=1;i<=n-3;i++) { x = x^i; sb.append(i).append(" "); } sb.append((1 << 29) + " " + (1 << 30) + " ").append(x).append("\n"); } output.write(sb.toString()); output.flush(); } } //Fast Input class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
bab612b7e0079fdd921b7447e6750754
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; public class G { static final long mod = (long) 1e9 + 7l; private static void solve(int t){ int n = fs.nextInt(); int ans[] = new int[n]; ans[0]=1; ans[1]=2; int x = 3; for (int i = 2; i < ans.length-1; i++) { ans[i] = (i-1)*4; x^=ans[i]; } ans[n-1]=x; for (int i = 0; i < n; i++) { out.print(ans[i]+" "); } out.println(); } private static int[] sortByCollections(int[] arr) { ArrayList<Integer> ls = new ArrayList<>(arr.length); for (int i = 0; i < arr.length; i++) { ls.add(arr[i]); } Collections.sort(ls); for (int i = 0; i < arr.length; i++) { arr[i] = ls.get(i); } return arr; } public static void main(String[] args) { fs = new FastScanner(); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); int t = fs.nextInt(); for (int i = 1; i <= t; i++) solve(t); out.close(); // System.err.println( System.currentTimeMillis() - s + "ms" ); } static boolean DEBUG = true; static PrintWriter out; static FastScanner fs; static void trace(Object... o) { if (!DEBUG) return; System.err.println(Arrays.deepToString(o)); } static void pl(Object o) { out.println(o); } static void p(Object o) { out.print(o); } static long gcd(long a, long b) { return (b == 0) ? a : gcd(b, a % b); } static int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } static void sieveOfEratosthenes(int n, int factors[]) { factors[1] = 1; for (int p = 2; p * p <= n; p++) { if (factors[p] == 0) { factors[p] = p; for (int i = p * p; i <= n; i += p) factors[i] = p; } } } static long mul(long a, long b) { return a * b % mod; } static long fact(int x) { long ans = 1; for (int i = 2; i <= x; i++) ans = mul(ans, i); return ans; } static long fastPow(long base, long exp) { if (exp == 0) return 1; long half = fastPow(base, exp / 2); if (exp % 2 == 0) return mul(half, half); return mul(half, mul(half, base)); } static long modInv(long x) { return fastPow(x, mod - 2); } static long nCk(int n, int k) { return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n - k)))); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String next() { while (!st.hasMoreElements()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } static class _Scanner { InputStream is; _Scanner(InputStream is) { this.is = is; } byte[] bb = new byte[1 << 15]; int k, l; byte getc() throws IOException { if (k >= l) { k = 0; l = is.read(bb); if (l < 0) return -1; } return bb[k++]; } byte skip() throws IOException { byte b; while ((b = getc()) <= 32) ; return b; } int nextInt() throws IOException { int n = 0; for (byte b = skip(); b > 32; b = getc()) n = n * 10 + b - '0'; return n; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
a443ba21d01b9094bb2bca4a4a2e01d7
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
//package codeForces; import java.util.Scanner; import java.util.stream.IntStream; public class G_1722 { static Scanner sc = new Scanner(System.in); static void solve() { int n = Integer.parseInt(sc.next()); int temp = 0; for (int i = 3; i <= n; i++) { temp ^= i; } System.out.print((1 << 25) + temp + " " + (1 << 25) + " "); for (int i = 3; i <= n; i++) { System.out.print(i + " "); } System.out.println(); } public static void main(String[] args) { // int t = 1; int t = Integer.parseInt(sc.next()); IntStream.range(0, t).forEach(s -> solve()); } // TEMPLATES public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz"; static int[] setArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } return arr; } static void printArray(int[] arr) { for (int j : arr) { System.out.print(j + " "); } } static int[][] setMatrix(int n, int m) { int[][] matrix = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = sc.nextInt(); } } return matrix; } static void printMatrix(int n, int m, int[][] matrix) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); } } static long binPow(int x, int y) { if (y == 0) { return 1; } if (y == 1) { return x; } long answer = binPow(x, y / 2); if (y % 2 == 0) { return answer * answer; } return answer * answer * x; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
ad9c3a3f0fa6b5c728dec2b67c15fe63
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { //code BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0) { int n=Integer.parseInt(br.readLine()); int case1=0; int case2=0; for(int i=0;i<n-2;i++) { case1=case1^i; case2=case2^(i+1); } long addlast= ((long)1<<31)-1; StringBuffer sb=new StringBuffer(); if(case1!=0) { for(int i=0;i<n-2;i++) { sb.append(i+" "); } case1=(int)(case1^addlast); sb.append(addlast+" "+case1); System.out.println(sb); } else { for(int i=1;i<=n-2;i++) { sb.append(i+" "); } case2=(int)(case2^addlast); sb.append(addlast+" "+case2); System.out.println(sb); } } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
e0fe0d4f358e07b839c528e68d5e3df9
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main { static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); static int dx[]={0,0,-1,1,-1,-1,1,1},dy[]={-1,1,0,0,-1,1,-1,1}; static final double pi=3.1415926536; static long mod=1000000007; // static long mod=998244353; static int MAX=Integer.MAX_VALUE; static int MIN=Integer.MIN_VALUE; static long MAXL=Long.MAX_VALUE; static long MINL=Long.MIN_VALUE; static ArrayList<pair> graph[]; static long fact[]; static long seg[]; static int dp[][]; // static long dp[][]; public static void main (String[] args) throws java.lang.Exception { // code goes here int t=I(); outer:while(t-->0) { int n=I(); if(n%2==0){ long a[]=new long[n/2]; long b[]=new long[n/2]; for(int i=1;i<=n/2;i++){ a[i-1]=i; b[i-1]=i; } if((n/2)%2==0){ for(int i=0;i<n/2;i++){ a[i]+=Math.pow(2,30); } }else{ for(int i=1;i<n/2;i++){ a[i]+=Math.pow(2,30); } a[0]+=Math.pow(2,29); a[1]+=Math.pow(2,29); } long temp[]=new long[n]; int in=0; for(int i=0;i<n/2;i++){ temp[in++]=a[i]; temp[in++]=b[i]; } printArray(temp); }else{ long a[]=new long[n-n/2]; long b[]=new long[n/2]; a[0]=0; for(int i=1;i<=n/2;i++){ a[i]=i; b[i-1]=i; } if((n-n/2)%2==0){ for(int i=0;i<n-n/2;i++){ a[i]+=Math.pow(2,30); } }else{ for(int i=1;i<n-n/2;i++){ a[i]+=Math.pow(2,30); } } long temp[]=new long[n]; int in=0; for(int i=0;i<n-n/2;i++){ temp[in]=a[i]; in+=2; } in=1; for(int i=0;i<n/2;i++){ temp[in]=b[i]; in+=2; } printArray(temp); } } out.close(); } public static class pair { long a; long b; public pair(long aa,long bb) { a=aa; b=bb; } } public static class myComp implements Comparator<pair> { //sort in ascending order. public int compare(pair p1,pair p2) { if(p1.a==p2.a) return 0; else if(p1.a<p2.a) return -1; else return 1; } // sort in descending order. // public int compare(pair p1,pair p2) // { // if(p1.b==p2.b) // return 0; // else if(p1.b<p2.b) // return 1; // else // return -1; // } } // public static void setGraph(int n,int m)throws IOException // { // graph=new ArrayList[n+1]; // for(int i=0;i<=n;i++){ // graph[i]=new ArrayList<>(); // } // for(int i=0;i<m;i++){ // int u=I(),v=I(); // graph[u].add(v); // graph[v].add(u); // } // } //LOWER_BOUND and UPPER_BOUND functions //It returns answer according to zero based indexing. public static int lower_bound(pair[] arr,int X,int start, int end) //start=0,end=n-1 { if(start>end)return -1; // if(arr.get(end)<X)return end; if(arr[end].a<X)return end; // if(arr.get(start)>X)return -1; if(arr[start].a>X)return -1; int left=start,right=end; while(left<right){ int mid=(left+right)/2; if(arr[mid].a==X){ // if(arr.get(mid)==X){ //Returns last index of lower bound value. if(mid<end && arr[mid+1].a==X){ // if(mid<end && arr.get(mid+1)==X){ left=mid+1; }else{ return mid; } } // if(arr.get(mid)==X){ //Returns first index of lower bound value. // if(arr[mid]==X){ // // if(mid>start && arr.get(mid-1)==X){ // if(mid>start && arr[mid-1]==X){ // right=mid-1; // }else{ // return mid; // } // } else if(arr[mid].a>X){ // else if(arr.get(mid)>X){ if(mid>start && arr[mid-1].a<X){ // if(mid>start && arr.get(mid-1)<X){ return mid-1; }else{ right=mid-1; } }else{ if(mid<end && arr[mid+1].a>X){ // if(mid<end && arr.get(mid+1)>X){ return mid; }else{ left=mid+1; } } } return left; } //It returns answer according to zero based indexing. public static int upper_bound(long arr[],long X,int start,int end) //start=0,end=n-1 { if(arr[0]>=X)return start; if(arr[arr.length-1]<X)return -1; int left=start,right=end; while(left<right){ int mid=(left+right)/2; if(arr[mid]==X){ //returns first index of upper bound value. if(mid>start && arr[mid-1]==X){ right=mid-1; }else{ return mid; } } // if(arr[mid]==X){ //returns last index of upper bound value. // if(mid<end && arr[mid+1]==X){ // left=mid+1; // }else{ // return mid; // } // } else if(arr[mid]>X){ if(mid>start && arr[mid-1]<X){ return mid; }else{ right=mid-1; } }else{ if(mid<end && arr[mid+1]>X){ return mid+1; }else{ left=mid+1; } } } return left; } //END //Segment Tree Code public static void buildTree(long a[],int si,int ss,int se) { if(ss==se){ seg[si]=a[ss]; return; } int mid=(ss+se)/2; buildTree(a,2*si+1,ss,mid); buildTree(a,2*si+2,mid+1,se); seg[si]=max(seg[2*si+1],seg[2*si+2]); } // public static void update(int si,int ss,int se,int pos,int val) // { // if(ss==se){ // // seg[si]=val; // return; // } // int mid=(ss+se)/2; // if(pos<=mid){ // update(2*si+1,ss,mid,pos,val); // }else{ // update(2*si+2,mid+1,se,pos,val); // } // // seg[si]=min(seg[2*si+1],seg[2*si+2]); // if(seg[2*si+1].a < seg[2*si+2].a){ // seg[si].a=seg[2*si+1].a; // seg[si].b=seg[2*si+1].b; // }else{ // seg[si].a=seg[2*si+2].a; // seg[si].b=seg[2*si+2].b; // } // } public static long query1(int si,int ss,int se,int qs,int qe) { if(qs>se || qe<ss)return 0; if(ss>=qs && se<=qe)return seg[si]; int mid=(ss+se)/2; long p1=query1(2*si+1,ss,mid,qs,qe); long p2=query1(2*si+2,mid+1,se,qs,qe); return max(p1,p2); } public static void merge(ArrayList<Integer> f,ArrayList<Integer> a,ArrayList<Integer> b) { int i=0,j=0; while(i<a.size() && j<b.size()){ if(a.get(i)<=b.get(j)){ f.add(a.get(i)); i++; }else{ f.add(b.get(j)); j++; } } while(i<a.size()){ f.add(a.get(i)); i++; } while(j<b.size()){ f.add(b.get(j)); j++; } } //Segment Tree Code end //Prefix Function of KMP Algorithm public static int[] KMP(char c[],int n) { int pi[]=new int[n]; for(int i=1;i<n;i++){ int j=pi[i-1]; while(j>0 && c[i]!=c[j]){ j=pi[j-1]; } if(c[i]==c[j])j++; pi[i]=j; } return pi; } public static long kadane(long a[],int n) //largest sum subarray { long max_sum=Long.MIN_VALUE,max_end=0; for(int i=0;i<n;i++){ max_end+=a[i]; if(max_sum<max_end){max_sum=max_end;} if(max_end<0){max_end=0;} } return max_sum; } public static ArrayList<Long> primeFact(long x) { ArrayList<Long> arr=new ArrayList<>(); if(x%2==0){ arr.add(2L); while(x%2==0){ x/=2; } } for(long i=3;i*i<=x;i+=2){ if(x%i==0){ arr.add(i); while(x%i==0){ x/=i; } } } if(x>0){ arr.add(x); } return arr; } public static long nPr(int n,int r) { long ans=divide(fact(n),fact(n-r),mod); return ans; } public static long nCr(int n,int r) { long ans=divide(fact[n],mul(fact[n-r],fact[r]),mod); return ans; } public static boolean isSorted(int a[]) { int n=a.length; for(int i=0;i<n-1;i++){ if(a[i]>a[i+1])return false; } return true; } public static boolean isSorted(long a[]) { int n=a.length; for(int i=0;i<n-1;i++){ if(a[i]>a[i+1])return false; } return true; } public static int computeXOR(int n) //compute XOR of all numbers between 1 to n. { if (n % 4 == 0) return n; if (n % 4 == 1) return 1; if (n % 4 == 2) return n + 1; return 0; } public static int np2(int x) { x--; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x++; return x; } public static int hp2(int x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } public static long hp2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } public static ArrayList<Integer> primeSieve(int n) { ArrayList<Integer> arr=new ArrayList<>(); boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int i = 2; i <= n; i++) { if (prime[i] == true) arr.add(i); } return arr; } // Fenwick / BinaryIndexed Tree USE IT - FenwickTree ft1=new FenwickTree(n); public static class FenwickTree { int farr[]; int n; public FenwickTree(int c) { n=c+1; farr=new int[n]; } // public void update_range(int l,int r,long p) // { // update(l,p); // update(r+1,(-1)*p); // } public void update(int x,int p) { for(;x<n;x+=x&(-x)) { farr[x]+=p; } } public int get(int x) { int ans=0; for(;x>0;x-=x&(-x)) { ans=ans+farr[x]; } return ans; } } //Disjoint Set Union //NOTE: call find function for all the index in the par array at last, //in order to set parent of every index properly. public static class DSU { int par[],rank[]; public DSU(int c) { par=new int[c+1]; rank=new int[c+1]; for(int i=0;i<=c;i++) { par[i]=i; rank[i]=0; } } public int find(int a) { if(a==par[a]) return a; return par[a]=find(par[a]); } public void union(int a,int b) { int a_rep=find(a),b_rep=find(b); if(a_rep==b_rep) return; if(rank[a_rep]<rank[b_rep]) par[a_rep]=b_rep; else if(rank[a_rep]>rank[b_rep]) par[b_rep]=a_rep; else { par[b_rep]=a_rep; rank[a_rep]++; } } } public static boolean isVowel(char c) { if(c=='a' || c=='e' || c=='i' || c=='u' || c=='o')return true; return false; } public static boolean isInteger(double N) { int X = (int)N; double temp2 = N - X; if (temp2 > 0) { return false; } return true; } public static boolean isPalindrome(String s) { int n=s.length(); for(int i=0;i<=n/2;i++){ if(s.charAt(i)!=s.charAt(n-i-1)){ return false; } } return true; } public static int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } public static long gcd(long a,long b) { if(b==0) return a; else return gcd(b,a%b); } public static long fact(long n) { long fact=1; for(long i=2;i<=n;i++){ fact=((fact%mod)*(i%mod))%mod; } return fact; } public static long fact(int n) { long fact=1; for(int i=2;i<=n;i++){ fact=((fact%mod)*(i%mod))%mod; } return fact; } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static boolean isPrime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static void printArray(long a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(int a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(char a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]); } out.println(); } public static void printArray(String a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(boolean a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(pair a[]) { for(pair p:a){ out.println(p.a+"->"+p.b); } } public static void printArray(int a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(String a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(boolean a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(long a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(char a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(ArrayList<?> arr) { for(int i=0;i<arr.size();i++){ out.print(arr.get(i)+" "); } out.println(); } public static void printMapI(HashMap<?,?> hm){ for(Map.Entry<?,?> e:hm.entrySet()){ out.println(e.getKey()+"->"+e.getValue()); }out.println(); } public static void printMap(HashMap<Long,ArrayList<Integer>> hm){ for(Map.Entry<Long,ArrayList<Integer>> e:hm.entrySet()){ out.print(e.getKey()+"->"); ArrayList<Integer> arr=e.getValue(); for(int i=0;i<arr.size();i++){ out.print(arr.get(i)+" "); }out.println(); } } public static void printGraph(ArrayList<Integer> graph[]) { int n=graph.length; for(int i=0;i<n;i++){ out.print(i+"->"); for(int j:graph[i]){ out.print(j+" "); }out.println(); } } //Modular Arithmetic public static long add(long a,long b) { a+=b; if(a>=mod)a-=mod; return a; } public static long sub(long a,long b) { a-=b; if(a<0)a+=mod; return a; } public static long mul(long a,long b) { return ((a%mod)*(b%mod))%mod; } public static long divide(long a,long b,long m) { a=mul(a,modInverse(b,m)); return a; } public static long modInverse(long a,long m) { int x=0,y=0; own p=new own(x,y); long g=gcdExt(a,m,p); if(g!=1){ out.println("inverse does not exists"); return -1; }else{ long res=((p.a%m)+m)%m; return res; } } public static long gcdExt(long a,long b,own p) { if(b==0){ p.a=1; p.b=0; return a; } int x1=0,y1=0; own p1=new own(x1,y1); long gcd=gcdExt(b,a%b,p1); p.b=p1.a - (a/b) * p1.b; p.a=p1.b; return gcd; } public static long pwr(long m,long n) { long res=1; if(m==0) return 0; while(n>0) { if((n&1)!=0) { res=(res*m); } n=n>>1; m=(m*m); } return res; } public static long modpwr(long m,long n) { long res=1; m=m%mod; if(m==0) return 0; while(n>0) { if((n&1)!=0) { res=(res*m)%mod; } n=n>>1; m=(m*m)%mod; } return res; } public static class own { long a; long b; public own(long val,long index) { a=val; b=index; } } //Modular Airthmetic public static void sort(int[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static void sort(char[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { char tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static void sort(long[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } //max & min public static int max(int a,int b){return Math.max(a,b);} public static int min(int a,int b){return Math.min(a,b);} public static int max(int a,int b,int c){return Math.max(a,Math.max(b,c));} public static int min(int a,int b,int c){return Math.min(a,Math.min(b,c));} public static long max(long a,long b){return Math.max(a,b);} public static long min(long a,long b){return Math.min(a,b);} public static long max(long a,long b,long c){return Math.max(a,Math.max(b,c));} public static long min(long a,long b,long c){return Math.min(a,Math.min(b,c));} public static int maxinA(int a[]){int n=a.length;int mx=a[0];for(int i=1;i<n;i++){mx=max(mx,a[i]);}return mx;} public static long maxinA(long a[]){int n=a.length;long mx=a[0];for(int i=1;i<n;i++){mx=max(mx,a[i]);}return mx;} public static int mininA(int a[]){int n=a.length;int mn=a[0];for(int i=1;i<n;i++){mn=min(mn,a[i]);}return mn;} public static long mininA(long a[]){int n=a.length;long mn=a[0];for(int i=1;i<n;i++){mn=min(mn,a[i]);}return mn;} public static long suminA(int a[]){int n=a.length;long sum=0;for(int i=0;i<n;i++){sum+=a[i];}return sum;} public static long suminA(long a[]){int n=a.length;long sum=0;for(int i=0;i<n;i++){sum+=a[i];}return sum;} //end public static int[] I(int n)throws IOException{int a[]=new int[n];for(int i=0;i<n;i++){a[i]=I();}return a;} public static long[] IL(int n)throws IOException{long a[]=new long[n];for(int i=0;i<n;i++){a[i]=L();}return a;} public static long[] prefix(int a[]){int n=a.length;long pre[]=new long[n];pre[0]=a[0];for(int i=1;i<n;i++){pre[i]=pre[i-1]+a[i];}return pre;} public static long[] prefix(long a[]){int n=a.length;long pre[]=new long[n];pre[0]=a[0];for(int i=1;i<n;i++){pre[i]=pre[i-1]+a[i];}return pre;} public static int I()throws IOException{return sc.I();} public static long L()throws IOException{return sc.L();} public static String S()throws IOException{return sc.S();} public static double D()throws IOException{return sc.D();} } class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } String next(){ while (st == null || !st.hasMoreElements()){ try { st = new StringTokenizer(br.readLine()); } catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } int I(){ return Integer.parseInt(next());} long L(){ return Long.parseLong(next());} double D(){return Double.parseDouble(next());} String S(){ String str = ""; try { str = br.readLine(); } catch (IOException e){ e.printStackTrace(); } return str; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
1e20924c6ecd6ce5ef3992de0d8945cd
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int n=sc.nextInt(); int case1=0,case2=0; for(int j=0;j<n-2;j++) { case1^=j; case2^=(j+1); } if(case1!=0) { int pre=Integer.MAX_VALUE-1; for(int j=0;j<n-2;j++) { System.out.print(j+" "); } case1^=pre; System.out.println(pre+" "+case1); } else { int pre=Integer.MAX_VALUE-1; for(int j=0;j<n-2;j++) { System.out.print((j+1)+" "); } case2^=pre; System.out.println(pre+" "+case2); } } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
b829f0db39b78620ee4496eb6bdfd402
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args){ MyScanner scanner = new MyScanner(); int numOfTests = scanner.nextInt(); for(int t = 1; t <= numOfTests; t++){ int n = scanner.nextInt(); solve(n); } out.close(); } private static void solve(int n){ int[] res = new int[n]; int xor = 0; for(int i = 1; i <= n - 3; i++){ res[i-1] = i; xor ^= i; } res[n - 3] = (1 << 30); xor ^= (1 << 30); res[n-2] = (1 << 29); xor ^= (1 << 29); res[n-1] = xor; verify(res); for(int i = 0; i < n; i++){ out.print(res[i]); if(i < n - 1){ out.print(" "); } } out.print("\n"); } private static void verify(int[] arr){ int odd = 0, even = 0; for(int i = 0; i < arr.length; i++){ if(i % 2 == 1){ odd ^= arr[i]; } else{ even ^= arr[i]; } } if(odd != even){ out.println(odd + " --- " + even); out.println("Wrong Answer"); } } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
c15edc6bf7d551a535231991aa907b45
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(reader.readLine()); while(n-- > 0){ int m = Integer.parseInt(reader.readLine()); int s = 0; for(int i = 3; i <= m;i++){ s ^=i; } System.out.print((1<<25)+s+" "+(1<<25)+" "); for(int i = 3;i<=m;i++){ System.out.print(i+" "); } System.out.println(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
6c6fea65b8ba12f2fa56da3228dba8ff
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
//package codeforces.round817div4; import java.io.*; import java.util.*; import static java.lang.Math.*; public class G { static InputReader in; static PrintWriter out; public static void main(String[] args) { //initReaderPrinter(true); initReaderPrinter(false); solve(in.nextInt()); //solve(1); } /* General tips 1. It is ok to fail, but it is not ok to fail for the same mistakes over and over! 2. Train smarter, not harder! 3. If you find an answer and want to return immediately, don't forget to flush before return! */ /* Read before practice 1. Set a timer based on a problem's difficulty level: 45 minutes at your current target practice level; 2. During a problem solving session, focus! Do not switch problems or even worse switch to do something else; 3. If fail to solve within timer limit, read editorials to get as little help as possible to get yourself unblocked; 4. If after reading the entire editorial and other people's code but still can not solve, move this problem to to-do list and re-try in the future. 5. Keep a practice log about new thinking approaches, good tricks, bugs; Review regularly; 6. Also try this new approach suggested by um_nik: Solve with no intention to read editorial. If getting stuck, skip it and solve other similar level problems. Wait for 1 week then try to solve again. Only read editorial after you solved a problem. 7. Remember to also submit in the original problem link (if using gym) so that the 1 v 1 bot knows which problems I have solved already. 8. Form the habit of writing down an implementable solution idea before coding! You've taken enough hits during contests because you rushed to coding! */ /* Read before contests and lockout 1 v 1 Mistakes you've made in the past contests: 1. Tried to solve without going through given test examples -> wasting time on solving a different problem than asked; 2. Rushed to coding without getting a comprehensive sketch of your solution -> implementation bugs and WA; Write down your idea step by step, no need to rush. It is always better to have all the steps considered before hand! Think about all the past contests that you have failed because slow implementation and implementation bugs! This will be greatly reduced if you take your time to get a thorough idea steps! 3. Forgot about possible integer overflow; When stuck: 1. Understand problem statements? Walked through test examples? 2. Take a step back and think about other approaches? 3. Check rank board to see if you can skip to work on a possibly easier problem? 4. If none of the above works, take a guess? */ static void solve(int testCnt) { for (int testNumber = 0; testNumber < testCnt; testNumber++) { int n = in.nextInt(); int[] ans = new int[n]; int xor = 0; for(int i = 0; i <= n - 3; i++) { ans[i] = i; xor ^= i; } if(xor == 0) { ans[0] = n - 2; xor ^= (n - 2); } ans[n - 2] = 1 << 30; ans[n - 1] = xor ^ ans[n - 2]; for(int v : ans) { out.print(v + " "); } out.println(); } out.close(); } static void initReaderPrinter(boolean test) { if (test) { try { in = new InputReader(new FileInputStream("src/input.in")); out = new PrintWriter(new FileOutputStream("src/output.out")); } catch (IOException e) { e.printStackTrace(); } } else { in = new InputReader(System.in); out = new PrintWriter(System.out); } } static class InputReader { BufferedReader br; StringTokenizer st; InputReader(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream), 32768); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } Integer[] nextIntArray(int n) { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArrayPrimitive(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArrayPrimitiveOneIndexed(int n) { int[] a = new int[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextInt(); return a; } Long[] nextLongArray(int n) { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long[] nextLongArrayPrimitive(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long[] nextLongArrayPrimitiveOneIndexed(int n) { long[] a = new long[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextLong(); return a; } String[] nextStringArray(int n) { String[] g = new String[n]; for (int i = 0; i < n; i++) g[i] = next(); return g; } List<Integer>[] readGraphOneIndexed(int n, int m) { List<Integer>[] adj = new List[n + 1]; for (int i = 0; i <= n; i++) { adj[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int u = nextInt(); int v = nextInt(); adj[u].add(v); adj[v].add(u); } return adj; } List<Integer>[] readGraphZeroIndexed(int n, int m) { List<Integer>[] adj = new List[n]; for (int i = 0; i < n; i++) { adj[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int u = nextInt() - 1; int v = nextInt() - 1; adj[u].add(v); adj[v].add(u); } return adj; } /* A more efficient way of building an undirected graph using int[] instead of ArrayList to store each node's neighboring nodes. 1-indexed. */ int[][] buildUndirectedGraph(int nodeCnt, int edgeCnt) { int[] end1 = new int[edgeCnt], end2 = new int[edgeCnt]; int[] edgeCntForEachNode = new int[nodeCnt + 1], idxForEachNode = new int[nodeCnt + 1]; for (int i = 0; i < edgeCnt; i++) { int u = in.nextInt(), v = in.nextInt(); edgeCntForEachNode[u]++; edgeCntForEachNode[v]++; end1[i] = u; end2[i] = v; } int[][] adj = new int[nodeCnt + 1][]; for (int i = 1; i <= nodeCnt; i++) { adj[i] = new int[edgeCntForEachNode[i]]; } for (int i = 0; i < edgeCnt; i++) { adj[end1[i]][idxForEachNode[end1[i]]] = end2[i]; idxForEachNode[end1[i]]++; adj[end2[i]][idxForEachNode[end2[i]]] = end1[i]; idxForEachNode[end2[i]]++; } return adj; } /* A more efficient way of building an undirected weighted graph using int[] instead of ArrayList to store each node's neighboring nodes. 1-indexed. */ int[][][] buildUndirectedWeightedGraph(int nodeCnt, int edgeCnt) { int[] end1 = new int[edgeCnt], end2 = new int[edgeCnt], weight = new int[edgeCnt]; int[] edgeCntForEachNode = new int[nodeCnt + 1], idxForEachNode = new int[nodeCnt + 1]; for (int i = 0; i < edgeCnt; i++) { int u = in.nextInt(), v = in.nextInt(), w = in.nextInt(); edgeCntForEachNode[u]++; edgeCntForEachNode[v]++; end1[i] = u; end2[i] = v; weight[i] = w; } int[][][] adj = new int[nodeCnt + 1][][]; for (int i = 1; i <= nodeCnt; i++) { adj[i] = new int[edgeCntForEachNode[i]][2]; } for (int i = 0; i < edgeCnt; i++) { adj[end1[i]][idxForEachNode[end1[i]]][0] = end2[i]; adj[end1[i]][idxForEachNode[end1[i]]][1] = weight[i]; idxForEachNode[end1[i]]++; adj[end2[i]][idxForEachNode[end2[i]]][0] = end1[i]; adj[end2[i]][idxForEachNode[end2[i]]][1] = weight[i]; idxForEachNode[end2[i]]++; } return adj; } /* A more efficient way of building a directed graph using int[] instead of ArrayList to store each node's neighboring nodes. 1-indexed. */ int[][] buildDirectedGraph(int nodeCnt, int edgeCnt) { int[] from = new int[edgeCnt], to = new int[edgeCnt]; int[] edgeCntForEachNode = new int[nodeCnt + 1], idxForEachNode = new int[nodeCnt + 1]; //from u to v: u -> v for (int i = 0; i < edgeCnt; i++) { int u = in.nextInt(), v = in.nextInt(); edgeCntForEachNode[u]++; from[i] = u; to[i] = v; } int[][] adj = new int[nodeCnt + 1][]; for (int i = 1; i <= nodeCnt; i++) { adj[i] = new int[edgeCntForEachNode[i]]; } for (int i = 0; i < edgeCnt; i++) { adj[from[i]][idxForEachNode[from[i]]] = to[i]; idxForEachNode[from[i]]++; } return adj; } /* A more efficient way of building a directed weighted graph using int[] instead of ArrayList to store each node's neighboring nodes. 1-indexed. */ int[][][] buildDirectedWeightedGraph(int nodeCnt, int edgeCnt) { int[] from = new int[edgeCnt], to = new int[edgeCnt], weight = new int[edgeCnt]; int[] edgeCntForEachNode = new int[nodeCnt + 1], idxForEachNode = new int[nodeCnt + 1]; //from u to v: u -> v for (int i = 0; i < edgeCnt; i++) { int u = in.nextInt(), v = in.nextInt(), w = in.nextInt(); edgeCntForEachNode[u]++; from[i] = u; to[i] = v; weight[i] = w; } int[][][] adj = new int[nodeCnt + 1][][]; for (int i = 1; i <= nodeCnt; i++) { adj[i] = new int[edgeCntForEachNode[i]][2]; } for (int i = 0; i < edgeCnt; i++) { adj[from[i]][idxForEachNode[from[i]]][0] = to[i]; adj[from[i]][idxForEachNode[from[i]]][1] = weight[i]; idxForEachNode[from[i]]++; } return adj; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
ca06d772c785820d4eda07cc9ba361db
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main { // Alphabet size (# of symbols) public static class Pair implements Comparable < Pair > { int d; int i; Pair(int i, int d) { this.d = d; this.i = i; System.out.println("TEst"); } public int compareTo(Pair o) { if (this.d == o.d) return this.i - o.i; if (this.d < o.d) return -1; else return 1; } } public static class SegmentTree { long[] st; long[] lazy; int n; SegmentTree(long[] arr, int n) { this.n = n; st = new long[4 * n]; lazy = new long[4 * n]; construct(arr, 0, n - 1, 0); } public long construct(long[] arr, int si, int ei, int node) { if (si == ei) { st[node] = arr[si]; return arr[si]; } int mid = (si + ei) / 2; long left = construct(arr, si, mid, 2 * node + 1); long right = construct(arr, mid + 1, ei, 2 * node + 2); st[node] = left + right; return st[node]; } public long get(int l, int r) { return get(0, n - 1, l, r, 0); } public long get(int si, int ei, int l, int r, int node) { if (r < si || l > ei) return 0; if (lazy[node] != 0) { st[node] += lazy[node] * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += lazy[node]; lazy[2 * node + 2] += lazy[node]; } lazy[node] = 0; } if (l <= si && r >= ei) return st[node]; int mid = (si + ei) / 2; return get(si, mid, l, r, 2 * node + 1) + get(mid + 1, ei, l, r, 2 * node + 2); } public void update(int index, int value) { update(0, n - 1, index, 0, value); } public void update(int si, int ei, int index, int node, int val) { if (si == ei) { st[node] = val; return; } int mid = (si + ei) / 2; if (index <= mid) { update(si, mid, index, 2 * node + 1, val); } else { update(mid + 1, ei, index, 2 * node + 2, val); } st[node] = st[2 * node + 1] + st[2 * node + 2]; } public void rangeUpdate(int l, int r, int val) { rangeUpdate(0, n - 1, l, r, 0, val); } public void rangeUpdate(int si, int ei, int l, int r, int node, int val) { if (r < si || l > ei) return; if (lazy[node] != 0) { st[node] += lazy[node] * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += lazy[node]; lazy[2 * node + 2] += lazy[node]; } lazy[node] = 0; } if (l <= si && r >= ei) { st[node] += val * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += val; lazy[2 * node + 2] += val; } return; } int mid = (si + ei) / 2; rangeUpdate(si, mid, l, r, 2 * node + 1, val); rangeUpdate(mid + 1, ei, l, r, 2 * node + 2, val); st[node] = st[2 * node + 1] + st[2 * node + 2]; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static int count = 0; public static void main(String[] args) throws IOException { if (System.getProperty("ONLINE_JUDGE") == null) { try { System.setIn(new FileInputStream(new File("input.txt"))); System.setOut(new PrintStream(new File("output.txt"))); } catch (Exception e) { } } Reader sc = new Reader(); int tc = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (tc-- > 0) { int n = sc.nextInt(); int[] arr = new int[n]; int xor = 0; for (int i = 0; i < n - 2; i++) { xor ^= i; arr[i] = i; } if (xor == 0) { arr[0] = n - 2; xor ^= arr[0]; arr[n - 2] = (1 << 30); arr[n - 1] = (xor) | (1 << 30); } else { arr[n - 2] = (1 << 30); arr[n - 1] = (xor) | (1 << 30); } for (int i = 0; i < n; i++) sb.append(arr[i] + " "); sb.append("\n"); } System.out.println(sb); } public static int[][] matrixExpo(int[][] mat, int n) { int[][] res = new int[2][2]; for (int i = 0; i < 2; i++) res[i][i] = 1; while (n > 0) { if (n % 2 == 0) { mat = multiplyMatrix(mat, mat); } else { res = multiplyMatrix(mat, res); mat = multiplyMatrix(mat, mat); } n = n / 2; } return res; } public static void print(int[][] mat) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(mat[i][j] + " "); } System.out.println(); } } public static int[][] multiplyMatrix(int[][] mat1, int[][] mat2) { int n = mat1.length; int[][] res = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int sum = 0; for (int k = 0; k < n; k++) { sum += (mat1[i][k] * mat2[k][j]); } res[i][j] = sum; } } return res; } public static int[] resultMat(int[][] mat, int[] arr) { int n = arr.length; int[] res = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { res[i] += (arr[j] * mat[j][i]); } } return res; } public static boolean contained(int[] arr, int k) { for (int ele : arr) { if (ele % k == 0) return true; } return false; } static long power(long x, long y, long p) { long res = 1; // Initialize result // Update x if it is more // than or equal to p x = x % p; while (y > 0) { // If y is odd, multiply // x with the result if ((y & 1) > 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } public static int countBit(int n) { int count = 0; while (n > 0) { count += 1; n /= 2; } return count; } public static int get(int[] dsu, int x) { if (dsu[x] == x) return x; int k = get(dsu, dsu[x]); dsu[x] = k; return k; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static int Xor(int n) { if (n % 4 == 0) return n; // If n%4 gives remainder 1 if (n % 4 == 1) return 1; // If n%4 gives remainder 2 if (n % 4 == 2) return n + 1; // If n%4 gives remainder 3 return 0; } public static long pow(long a, long b, long mod) { long res = 1; while (b > 0) { if ((b & 1) > 0) res = (res * a) % mod; b = b >> 1; a = ((a % mod) * (a % mod)) % mod; } return (res % mod + mod) % mod; } public static double digit(long num) { return Math.floor(Math.log10(num) + 1); } public static void pattern(int n) { int k = n; int p = 1; while (k-- > 0) { for (int i = 1; i <= k; i++) { System.out.print(" "); } for (int i = 1; i <= p; i++) System.out.print("* "); System.out.println(); p += 1; } } static int upperBound(ArrayList<Long> arr, long key) { int mid, N = arr.size(); // Initialise starting index and // ending index int low = 0; int high = N; // Till low is less than high while (low < high && low != N) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is greater than or equal // to arr[mid], then find in // right subarray if (key >= arr.get(mid)) { low = mid + 1; } // If key is less than arr[mid] // then find in left subarray else { high = mid; } } // If key is greater than last element which is // array[n-1] then upper bound // does not exists in the array return low; } static int lowerBound(ArrayList<Long> array, long key) { // Initialize starting index and // ending index int low = 0, high = array.size(); int mid; // Till high does not crosses low while (low < high) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is less than or equal // to array[mid], then find in // left subarray if (key <= array.get(mid)) { high = mid; } // If key is greater than array[mid], // then find in right subarray else { low = mid + 1; } } // If key is greater than last element which is // array[n-1] then lower bound // does not exists in the array if (low < array.size() && array.get(low) < key) { low++; } // Returning the lower_bound index return low; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
307048d3be3c3f9882cad6f359550c28
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class A { public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public static void print(int[] a) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); } public static String concat(String s1, String s2) { return new StringBuilder(s1).append(s2).toString(); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static boolean isPrime(int n) { if (n <= 1) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); System.out.println(); int t1 = sc.nextInt(); outer: while (t1-- > 0) { int n = sc.nextInt(); int odd = 0,even = 0; int a = 0,b = 0; for (int i = 0;i<n;i++) { if (i%2 == 0) { odd^=i; }else { even^=i; } } if (odd == even) { for (int i = 0;i<n;i++) { out.print(i+ " "); } }else { odd = even = 0; for (int i = 0;i<n-2;i++) { if (i%2 == 0) { odd^=i; }else { even^=i; } } boolean tt = false; if (odd == even) { tt= true; odd^=300000; } a = Integer.MAX_VALUE-odd; b = Integer.MAX_VALUE-even; for (int i = 0;i<n-2;i++) { if (tt) { out.print(300000+ " "); tt = false; continue; } out.print(i+" "); } out.print(a+" "+b); } out.println(); } out.close(); } static class Pair implements Comparable<Pair> { long first; long second; public Pair(long first, long second) { this.first = first; this.second = second; } public int compareTo(Pair p) { if (first != p.first) return Long.compare(first, p.first); else if (second != p.second) return Long.compare(second, p.second); else return 0; } } static class Tuple implements Comparable<Tuple> { long first; long second; long third; public Tuple(long a, long b, long c) { first = a; second = b; third = c; } public int compareTo(Tuple t) { if (first != t.first) return Long.compare(first, t.first); else if (second != t.second) return Long.compare(second, t.second); else if (third != t.third) return Long.compare(third, t.third); else return 0; } } static final Random random = new Random(); static void shuffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int r = random.nextInt(n), temp = a[r]; a[r] = a[i]; a[i] = temp; } Arrays.sort(a); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } int[] readArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
830d6df0c501426fe22e70ea103de3bf
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String args[]) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(in.readLine()); while (t-- > 0) { StringTokenizer st1 = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st1.nextToken()); List<Integer> getPowersOf2 = block(n); //out.println("For input n=" + n); int magic = 30; Set<Integer> set1 = new HashSet<>(); Set<Integer> set2 = new HashSet<>(); for (int i=2; i<getPowersOf2.size(); i++) { int power = getPowersOf2.get(i); if (power == 0) continue; int val = (int)Math.pow(2,i); //out.print(""); for (int j=0; j<val/2; j++) { int temp = j | (1 << magic); // if (temp == 0) // out.println(0); // else // printTheNum(out, temp); set1.add(temp); } // out.println(); for (int j=val/2; j<val; j++) { int temp = j | (1 << magic); // if (temp == 0) // out.println(0); // else // printTheNum(out, temp); set2.add(temp); } magic--; } // When i==0 and i==1, if it has power (i.e. for num 3) if (getPowersOf2.size() >= 2 && getPowersOf2.get(0) == 1 && getPowersOf2.get(1) == 1) { set1.add(2); set1.add(3); set2.add(1); // out.println("Adding 10 and 11 to set 1"); // out.println("Adding 01 to set 2"); } // When i==0, if it has power (i.e. for num 1) if (getPowersOf2.size() >= 1 && getPowersOf2.get(0) == 1 && (getPowersOf2.size() == 1 || getPowersOf2.get(1) == 0)) { set1.add(0); // out.println("Adding 0 to set 1"); } // When i==1, if it has power (i.e. for num 2) if (getPowersOf2.size() >= 1 && getPowersOf2.get(1) == 1 && getPowersOf2.get(0) == 0) { int temp1 = 1<<30; int temp2 = 1<<magic; magic--; int tempToRemove = 1 | temp1; int tempToAdd = temp1 | temp2; set1.remove(tempToRemove); set1.add(tempToAdd); set2.add(temp2); set2.add(1); // out.println("Removing " + toBinary(tempToRemove) + " from set 1"); // out.println("Adding " + toBinary(tempToAdd) + " to set 1"); // // out.println("Adding " + toBinary(temp2) + " to set 2"); // out.println("Adding 1 to set 2"); } // int xor1 = 0; // int xor2 = 0; //// out.println("Set1 : "); // for(int x : set1) { // // out.println(toBinary(x)); // xor1 ^= x; // } //// out.println("Set2 : "); // for(int x : set2) { //// out.println(toBinary(x)); // xor2 ^= x; // } // if (xor1 == xor2 && set1.size()+set2.size() == n) // out.println("Working for n = " + n); Iterator it1=set1.iterator(), it2=set2.iterator(); while (it1.hasNext() || it2.hasNext()) { if (it1.hasNext()) out.print(it1.next() + " "); if (it2.hasNext()) out.print(it2.next() + " "); } out.println(); } in.close(); out.close(); } private static void printTheNum(PrintWriter out, int temp) { out.println(toBinary(temp) + " "); // out.print(temp + " "); } private static String toBinary(int n) { if (n == 0) { return ""; } return toBinary(n / 2) + (n % 2); } private static List<Integer> block(long x) { List<Integer> v = new ArrayList<>(); while (x > 0) { v.add((int)x % 2); x = x / 2; } // // Displaying the output when // // the bit is '1' in binary // // equivalent of number. // for (int i = 0; i < v.size(); i++) // { // if (v.get(i) == 1) // { // System.out.print(i); // if (i != v.size() - 1) // System.out.print( ", "); // } // } // System.out.println(); return v; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
97575be0f0a6e4e54fe83f698b49c786
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.HashSet; import java.util.Random; public class Main { static InputReader sc; public static void main(String[] args) throws Exception { sc=new InputReader(System.in); Random random=new Random(); int T=sc.nextInt(); while(T-->0) { int n=sc.nextInt(); if(n==3) { System.out.println("2 1 3"); continue; } int[] ans=new int[n+1]; HashSet<Integer> set=new HashSet<>(); int len; if(n%2==0) len=n-2; else len=n-3; for(int i=1;i<=len;i++) { int t=-1; do { t=random.nextInt(1000000)+1; } while(set.contains(t)); set.add(t); ans[i]=t; } int t1=0,t2=0; while(t1==t2) { int t=-1; do { t=random.nextInt(50000000)+1; } while(set.contains(t)); set.add(t); ans[len]=t; for(int i=2;i<=len;i+=2) { t1^=ans[i-1]; t2^=ans[i]; } } String s1=Integer.toBinaryString(t1); String s2=Integer.toBinaryString(t2); while(s1.length()<31) s1="0"+s1; while(s2.length()<31) s2="0"+s2; char[] str1=s1.toCharArray(); char[] str2=s2.toCharArray(); int last1=0,last2=0; for(int i=str1.length-1,t=1;i>=0;i--,t*=2) { if(str1[i]=='0') last1+=t; } for(int i=str2.length-1,t=1;i>=0;i--,t*=2) { if(str2[i]=='0') last2+=t; } ans[len+1]=last1; ans[len+2]=last2; if(n%2!=0) ans[n]=0; for(int i=1;i<=n;i++) System.out.print(ans[i]+" "); System.out.println(); } } static class InputReader { BufferedReader br; public InputReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); } public int nextInt() throws IOException { int c = br.read(); while (c <= 32) { c = br.read(); } boolean negative = false; if (c == '-') { negative = true; c = br.read(); } int x = 0; while (c > 32) { x = x * 10 + c - '0'; c = br.read(); } return negative ? -x : x; } public long nextLong() throws IOException { int c = br.read(); while (c <= 32) { c = br.read(); } boolean negative = false; if (c == '-') { negative = true; c = br.read(); } long x = 0; while (c > 32) { x = x * 10 + c - '0'; c = br.read(); } return negative ? -x : x; } public String next() throws IOException { int c = br.read(); while (c <= 32) { c = br.read(); } StringBuilder sb = new StringBuilder(); while (c > 32) { sb.append((char) c); c = br.read(); } return sb.toString(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
6294cdf13fc0ffcfd275490fad3931cb
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; public class Solution { static Solution2 admin = new Solution2(); public static void main(String[] args) { admin.start(); } } class Solution2 { //---------------------------------INPUT READER-----------------------------------------// public BufferedReader br; StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String ns() { return next(); } int[] na(long n) {int[]ret=new int[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;} long[] nal(long n) {long[]ret=new long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;} Integer[] nA(long n) {Integer[]ret=new Integer[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;} Long[] nAl(long n) {Long[]ret=new Long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;} //--------------------------------------PRINTER------------------------------------------// PrintWriter w; void p(int i) {w.println(i);} void p(long l) {w.println(l);} void p(double d) {w.println(d);} void p(String s) { w.println(s);} void pr(int i) {w.print(i);} void pr(long l) {w.print(l);} void pr(double d) {w.print(d);} void pr(String s) { w.print(s);} void pl() {w.println();} //--------------------------------------VARIABLES-----------------------------------------// long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE; int ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE; long mod = 1000000007; { w = new PrintWriter(System.out); br = new BufferedReader(new InputStreamReader(System.in)); try {if(new File(System.getProperty("user.dir")).getName().equals("LOCAL")) { w = new PrintWriter(new OutputStreamWriter(new FileOutputStream("output.txt"))); br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));} } catch (Exception ignore) { } } //----------------------START---------------------// void start() { int t = ni(); while(t-- > 0) solve(); w.close(); } void solve() { int n = ni(); int[] ans = new int[n]; int xor_odd = 0, xor_even = 0; int at = 1; for(int i = 0; i < n-2; i++) { if(i%2==0) { if((xor_even ^ at ^ xor_odd) == 0) at++; xor_even ^= at; ans[i] = at; at++; } else { if((xor_even ^ xor_odd ^ at) == 0) at++; xor_odd ^= at; ans[i] = at; at++; } } ans[n-2] = 2 * at; ans[n-1] = ans[n-2] ^ xor_odd ^ xor_even; for(int i = 0; i < n; i++) { pr(ans[i] +" " ); } pl(); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
7a7fe31e40f239880687ec9c8f67a4b1
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class TaskG { public static void main(String[] args) { FastReader reader = new FastReader(); int tt = reader.nextInt(); // int tt = 1; for (; tt > 0; tt--) { int n = reader.nextInt(); int xor = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n-3; i++) { sb.append(i).append(" "); xor ^= i; } int n3 = n-3; int n2 = n-2; int n1 = n-1; xor ^= n3; xor ^= n2; if (xor < n1) { if (xor == n2) { n3 ^= 1 << 30; } else { n2 ^= 1 << 30; } n1 = xor ^ (1 << 30); } sb.append(n3).append(" ").append(n2).append(" ").append(n1); System.out.println(sb); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if (st.hasMoreTokens()) { str = st.nextToken("\n"); } else { str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
992694e9233837bd61e24021ce36570a
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for (int t = 0; t < T; t++) { int N = in.nextInt(); int[] res = new int[N]; for (int i = 0; i < N; i++) { if (i % 2 == 0) { res[i] = i / 2 + 1; } else { res[i] = (i / 2 + 1) ^ ((1 << 30) - 1); } } if (N % 4 == 3) { res[N - 1] = (1 << 30) - 1; } if (N % 4 == 1) { res[N - 1] = 0; } if (N % 4 == 2) { res[N - 1] ^= (1 << 30) - 1; res[N - 1] ^= 1 << 30; res[0] ^= 1 << 30; } for (int i = 0; i < N; i++) { out.print(res[i] + (i == N - 1 ? "\n" : " ")); } } out.close(); } static class Reader { BufferedReader in; StringTokenizer st; public Reader() { in = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } public String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } public String next() throws IOException { while (!st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } } public static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i : arr) { list.add(i); } Collections.sort(list); for (int i = 0; i < arr.length; i++) { arr[i] = list.get(i); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
ad342c7632c3c25796971789bc0b7b7a
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class G { static class Scan { private byte[] buf=new byte[1024]; private int index; private InputStream in; private int total; public Scan() { in=System.in; } public int scan()throws IOException { if(total<0) throw new InputMismatchException(); if(index>=total) { index=0; total=in.read(buf); if(total<=0) return -1; } return buf[index++]; } public int scanInt()throws IOException { int integer=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { integer*=10; integer+=n-'0'; n=scan(); } else throw new InputMismatchException(); } return neg*integer; } public double scanDouble()throws IOException { double doub=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)&&n!='.') { if(n>='0'&&n<='9') { doub*=10; doub+=n-'0'; n=scan(); } else throw new InputMismatchException(); } if(n=='.') { n=scan(); double temp=1; while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { temp/=10; doub+=(n-'0')*temp; n=scan(); } else throw new InputMismatchException(); } } return doub*neg; } public String scanString()throws IOException { StringBuilder sb=new StringBuilder(); int n=scan(); while(isWhiteSpace(n)) n=scan(); while(!isWhiteSpace(n)) { sb.append((char)n); n=scan(); } return sb.toString(); } private boolean isWhiteSpace(int n) { if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1) return true; return false; } } public static void sort(int arr[],int l,int r) { //sort(arr,0,n-1); if(l==r) { return; } int mid=(l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); merge(arr,l,mid,mid+1,r); } public static void merge(int arr[],int l1,int r1,int l2,int r2) { int tmp[]=new int[r2-l1+1]; int indx1=l1,indx2=l2; //sorting the two halves using a tmp array for(int i=0;i<tmp.length;i++) { if(indx1>r1) { tmp[i]=arr[indx2]; indx2++; continue; } if(indx2>r2) { tmp[i]=arr[indx1]; indx1++; continue; } if(arr[indx1]<arr[indx2]) { tmp[i]=arr[indx1]; indx1++; continue; } tmp[i]=arr[indx2]; indx2++; } //Copying the elements of tmp into the main array for(int i=0,j=l1;i<tmp.length;i++,j++) { arr[j]=tmp[i]; } } public static void sort(long arr[],int l,int r) { //sort(arr,0,n-1); if(l==r) { return; } int mid=(l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); merge(arr,l,mid,mid+1,r); } public static void merge(long arr[],int l1,int r1,int l2,int r2) { long tmp[]=new long[r2-l1+1]; int indx1=l1,indx2=l2; //sorting the two halves using a tmp array for(int i=0;i<tmp.length;i++) { if(indx1>r1) { tmp[i]=arr[indx2]; indx2++; continue; } if(indx2>r2) { tmp[i]=arr[indx1]; indx1++; continue; } if(arr[indx1]<arr[indx2]) { tmp[i]=arr[indx1]; indx1++; continue; } tmp[i]=arr[indx2]; indx2++; } //Copying the elements of tmp into the main array for(int i=0,j=l1;i<tmp.length;i++,j++) { arr[j]=tmp[i]; } } public static void main(String args[]) throws IOException { Scan input=new Scan(); StringBuilder ans=new StringBuilder(""); int test=input.scanInt(); int pow[]=new int[32]; pow[0]=1; for(int i=1;i<pow.length;i++) { pow[i]=2*pow[i-1]; } for(int tt=1;tt<=test;tt++) { int n=input.scanInt(); if(n==3) { ans.append("2 1 3\n"); continue; } if(n==4) { ans.append("2 1 3 0\n"); continue; } if(n==5) { ans.append("2 0 4 5 3\n"); continue; } int len=n/2; int arr1[]=new int[len]; int arr2[]=new int[len]; int xor1=0,xor2=0; for(int i=0;i<len-1;i++) { arr1[i]=i+1; if((len-1)%4==0) { arr1[i]++; } xor1^=arr1[i]; // if(xor1==arr1[i]) { // System.out.println(i); // } arr2[i]=i+1+100000000; if((len-1)%4==0) { arr2[i]++; } xor2^=arr2[i]; } arr1[len-1]=xor1; arr1[len-1]^=pow[19]; arr1[len-2]^=pow[19]; arr2[len-1]=xor2; arr2[len-1]^=pow[30]; arr2[len-2]^=pow[30]; for(int i=0;i<len;i++) { ans.append(arr1[i]+" "+arr2[i]+" "); } if(n%2==1) { ans.append(0); } ans.append("\n"); } System.out.print(ans); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
c0c2656cf1877c127bfbbfcd39196d32
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class G { static class Scan { private byte[] buf=new byte[1024]; private int index; private InputStream in; private int total; public Scan() { in=System.in; } public int scan()throws IOException { if(total<0) throw new InputMismatchException(); if(index>=total) { index=0; total=in.read(buf); if(total<=0) return -1; } return buf[index++]; } public int scanInt()throws IOException { int integer=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { integer*=10; integer+=n-'0'; n=scan(); } else throw new InputMismatchException(); } return neg*integer; } public double scanDouble()throws IOException { double doub=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)&&n!='.') { if(n>='0'&&n<='9') { doub*=10; doub+=n-'0'; n=scan(); } else throw new InputMismatchException(); } if(n=='.') { n=scan(); double temp=1; while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { temp/=10; doub+=(n-'0')*temp; n=scan(); } else throw new InputMismatchException(); } } return doub*neg; } public String scanString()throws IOException { StringBuilder sb=new StringBuilder(); int n=scan(); while(isWhiteSpace(n)) n=scan(); while(!isWhiteSpace(n)) { sb.append((char)n); n=scan(); } return sb.toString(); } private boolean isWhiteSpace(int n) { if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1) return true; return false; } } public static void sort(int arr[],int l,int r) { //sort(arr,0,n-1); if(l==r) { return; } int mid=(l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); merge(arr,l,mid,mid+1,r); } public static void merge(int arr[],int l1,int r1,int l2,int r2) { int tmp[]=new int[r2-l1+1]; int indx1=l1,indx2=l2; //sorting the two halves using a tmp array for(int i=0;i<tmp.length;i++) { if(indx1>r1) { tmp[i]=arr[indx2]; indx2++; continue; } if(indx2>r2) { tmp[i]=arr[indx1]; indx1++; continue; } if(arr[indx1]<arr[indx2]) { tmp[i]=arr[indx1]; indx1++; continue; } tmp[i]=arr[indx2]; indx2++; } //Copying the elements of tmp into the main array for(int i=0,j=l1;i<tmp.length;i++,j++) { arr[j]=tmp[i]; } } public static void sort(long arr[],int l,int r) { //sort(arr,0,n-1); if(l==r) { return; } int mid=(l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); merge(arr,l,mid,mid+1,r); } public static void merge(long arr[],int l1,int r1,int l2,int r2) { long tmp[]=new long[r2-l1+1]; int indx1=l1,indx2=l2; //sorting the two halves using a tmp array for(int i=0;i<tmp.length;i++) { if(indx1>r1) { tmp[i]=arr[indx2]; indx2++; continue; } if(indx2>r2) { tmp[i]=arr[indx1]; indx1++; continue; } if(arr[indx1]<arr[indx2]) { tmp[i]=arr[indx1]; indx1++; continue; } tmp[i]=arr[indx2]; indx2++; } //Copying the elements of tmp into the main array for(int i=0,j=l1;i<tmp.length;i++,j++) { arr[j]=tmp[i]; } } public static void main(String args[]) throws IOException { Scan input=new Scan(); StringBuilder ans=new StringBuilder(""); int test=input.scanInt(); int pow[]=new int[32]; pow[0]=1; for(int i=1;i<pow.length;i++) { pow[i]=2*pow[i-1]; } for(int tt=1;tt<=test;tt++) { int n=input.scanInt(); if(n==3) { ans.append("2 1 3\n"); continue; } if(n==4) { ans.append("2 1 3 0\n"); continue; } if(n==5) { ans.append("2 0 4 5 3\n"); continue; } int len=n/2; int arr1[]=new int[len]; int arr2[]=new int[len]; int xor1=0,xor2=0; for(int i=0;i<len-1;i++) { arr1[i]=i+1; if((len-1)%4==0) { arr1[i]++; } xor1^=arr1[i]; // if(xor1==arr1[i]) { // System.out.println(i); // } arr2[i]=i+1+100000000; if((len-1)%4==0) { arr2[i]++; } xor2^=arr2[i]; } arr1[len-1]=xor1; arr1[len-1]^=pow[19]; arr1[len-2]^=pow[19]; arr2[len-1]=xor2; arr2[len-1]^=pow[30]; arr2[len-2]^=pow[30]; for(int i=0;i<len;i++) { ans.append(arr1[i]+" "+arr2[i]+" "); } if(n%2==1) { ans.append(0); } ans.append("\n"); } System.out.print(ans); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
ddf048ef2e9e8bafe6be0360a73d4a4b
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class E { static class Scan { private byte[] buf=new byte[1024]; private int index; private InputStream in; private int total; public Scan() { in=System.in; } public int scan()throws IOException { if(total<0) throw new InputMismatchException(); if(index>=total) { index=0; total=in.read(buf); if(total<=0) return -1; } return buf[index++]; } public int scanInt()throws IOException { int integer=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { integer*=10; integer+=n-'0'; n=scan(); } else throw new InputMismatchException(); } return neg*integer; } public double scanDouble()throws IOException { double doub=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)&&n!='.') { if(n>='0'&&n<='9') { doub*=10; doub+=n-'0'; n=scan(); } else throw new InputMismatchException(); } if(n=='.') { n=scan(); double temp=1; while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { temp/=10; doub+=(n-'0')*temp; n=scan(); } else throw new InputMismatchException(); } } return doub*neg; } public String scanString()throws IOException { StringBuilder sb=new StringBuilder(); int n=scan(); while(isWhiteSpace(n)) n=scan(); while(!isWhiteSpace(n)) { sb.append((char)n); n=scan(); } return sb.toString(); } private boolean isWhiteSpace(int n) { if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1) return true; return false; } } public static void sort(int arr[],int l,int r) { //sort(arr,0,n-1); if(l==r) { return; } int mid=(l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); merge(arr,l,mid,mid+1,r); } public static void merge(int arr[],int l1,int r1,int l2,int r2) { int tmp[]=new int[r2-l1+1]; int indx1=l1,indx2=l2; //sorting the two halves using a tmp array for(int i=0;i<tmp.length;i++) { if(indx1>r1) { tmp[i]=arr[indx2]; indx2++; continue; } if(indx2>r2) { tmp[i]=arr[indx1]; indx1++; continue; } if(arr[indx1]<arr[indx2]) { tmp[i]=arr[indx1]; indx1++; continue; } tmp[i]=arr[indx2]; indx2++; } //Copying the elements of tmp into the main array for(int i=0,j=l1;i<tmp.length;i++,j++) { arr[j]=tmp[i]; } } public static void sort(long arr[],int l,int r) { //sort(arr,0,n-1); if(l==r) { return; } int mid=(l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); merge(arr,l,mid,mid+1,r); } public static void merge(long arr[],int l1,int r1,int l2,int r2) { long tmp[]=new long[r2-l1+1]; int indx1=l1,indx2=l2; //sorting the two halves using a tmp array for(int i=0;i<tmp.length;i++) { if(indx1>r1) { tmp[i]=arr[indx2]; indx2++; continue; } if(indx2>r2) { tmp[i]=arr[indx1]; indx1++; continue; } if(arr[indx1]<arr[indx2]) { tmp[i]=arr[indx1]; indx1++; continue; } tmp[i]=arr[indx2]; indx2++; } //Copying the elements of tmp into the main array for(int i=0,j=l1;i<tmp.length;i++,j++) { arr[j]=tmp[i]; } } public static void main(String args[]) throws IOException { Scan input=new Scan(); StringBuilder ans=new StringBuilder(""); int test=input.scanInt(); int pow[]=new int[32]; pow[0]=1; for(int i=1;i<pow.length;i++) { pow[i]=2*pow[i-1]; } for(int tt=1;tt<=test;tt++) { int n=input.scanInt(); if(n==3) { ans.append("2 1 3\n"); continue; } if(n==4) { ans.append("2 1 3 0\n"); continue; } if(n==5) { ans.append("2 0 4 5 3\n"); continue; } int len=n/2; int arr1[]=new int[len]; int arr2[]=new int[len]; int xor1=0,xor2=0; for(int i=0;i<len-1;i++) { arr1[i]=i+1; if((len-1)%4==0) { arr1[i]++; } xor1^=arr1[i]; // if(xor1==arr1[i]) { // System.out.println(i); // } arr2[i]=i+1+100000000; if((len-1)%4==0) { arr2[i]++; } xor2^=arr2[i]; } arr1[len-1]=xor1; arr1[len-1]^=pow[19]; arr1[len-2]^=pow[19]; arr2[len-1]=xor2; arr2[len-1]^=pow[30]; arr2[len-2]^=pow[30]; for(int i=0;i<len;i++) { ans.append(arr1[i]+" "+arr2[i]+" "); } if(n%2==1) { ans.append(0); } ans.append("\n"); } System.out.print(ans); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
67f6c7775d3fc457d3906d20cdbc628f
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
//package com.rajan.codeforces.contests.contest817; import java.io.*; public class ProblemG { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); int tt = Integer.parseInt(reader.readLine()); while (tt-- > 0) { int n = Integer.parseInt(reader.readLine()); int[] array = new int[n]; int xor = 0; for (int i = 0; i < n - 2; i++) { array[i] = i; xor ^= i; } array[n - 2] = (1 << 30); if (xor == 0) { for(int i=0;i<n-2;i++) { array[i] = i + 1; xor^=(i+1); } array[n - 1] = array[n - 2] ^ xor; } else { array[n - 1] = array[n - 2] ^ xor; } for (int i = 1; i <= n; i++) writer.write((i == 1 ? "" : " ") + array[i - 1]); writer.write("\n"); } writer.flush(); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
4b241a6dcea1090196c2a4165eabb279
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int g = Integer.parseInt(bf.readLine()); while (g-- > 0) { int a=Integer.parseInt(bf.readLine()); int[] k=new int[a]; if(a%2==1) a--; int b=a/2; int i=0; if(b%2==1 && a>=6){ i=6; k[0]=1; k[2]=2; k[4]=3; k[1]=13; k[3]=5; k[5]=8; } int x=32,p=0; while (i<a) { if(((x+p)&1)==0){ k[i]=x+p; k[i+1]=x+p+1; i+=2; } p++; } if(a==2){ k[0]=1; k[1]=2; k[2]=3; } for(int j=0; j<k.length; j++) System.out.print(k[j]+" "); System.out.println(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
4d81d78db26c1d4aa7fa6463c1464016
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; public class abc { public static void main (String[] args) throws java.lang.Exception { Scanner sc =new Scanner(System.in); int n1=sc.nextInt(); while(n1-->0){ int n=sc.nextInt(); int[]arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=i; } int pow=(int)(Math.log(n)/Math.log(2))+1; //System.out.println(pow); int val=(int)Math.pow(2, pow); if(n%4==1){ arr[n-1]=val; arr[1]+=val; } if(n%4==2){ arr[n-2]=val; arr[n-1]=val*3; arr[1]+=val*2; } if(n%4==3){ arr[n-3]=val; arr[n-2]=val*3; arr[n-1]=val*2; } for(int i:arr) System.out.print(i+" "); System.out.println(); // int va=arr[0]; // for(int i=2;i<n;i+=2) // va=va^arr[i]; // int v=arr[1]; // for(int i=3;i<n;i+=2) // v=v^arr[i]; // System.out.println(va+" "+v); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
0e6872ec042ecfdbd6a8d4a85202e689
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; // @author : Dinosparton public class test { static class Pair{ long x; int y; Pair(long x,int y){ this.x = x; this.y = y; } } static class Compare { void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { if(p1.x!=p2.x) { return (int)(p1.x - p2.x); } else { return (int)(p1.y - p2.y); } } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + " " + arr[i].y + " "); // } // System.out.println(); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String args[]) throws Exception { Scanner sc = new Scanner(); StringBuilder res = new StringBuilder(); int tc = sc.nextInt(); while(tc-->0) { int n = sc.nextInt(); if(n==3) { res.append("2 1 3"+"\n"); continue; } if(n%4==0) { int a[] = new int[n]; int start = 0; for(int i=0;i<n;i++) { a[i] = start; if(i%2==0) { start += 2; } else if(i%4==3) { start++; } else { start--; } } for(int i : a) { res.append(i+" "); } res.append("\n"); } else if(n%2==0) { int a[] = new int[n]; for(int i=0;i<n-2;i++) { a[i] = i+1; } int xor1 = 0; int xor2 = 0; for(int i=0;i<n;i++) { if(i%2==0) { xor1 ^= a[i]; } else { xor2 ^= a[i]; } } String s = Integer.toBinaryString(xor1); String t = Integer.toBinaryString(xor2); int cnt = (1<< Math.max(t.length(), s.length())); int ans = cnt; xor1 += cnt; xor2 += cnt; s = Integer.toBinaryString(xor1); t = Integer.toBinaryString(xor2); // System.out.println(s+" "+t); int i = s.length()-1; int j = t.length()-1; while(i>=0 && j>=0) { if(s.charAt(i)!=t.charAt(j)) { ans += (1<<s.length()-i-1); } i--; j--; } a[n-2] = cnt; a[n-1] = ans; for(int k : a) { res.append(k+" "); } res.append("\n"); } if(n%2!=0) { int a[] = new int[n]; int start = 0; for(int i=0;i<n-2;i++) { a[i] = start; if(i%2==0) { start += 2; } else if(i%4==3) { start++; } else { start--; } } int xor1 = 0; int xor2 = 0; for(int i=0;i<n;i++) { if(i%2==0) { xor1 ^= a[i]; } else { xor2 ^= a[i]; } } String s = Integer.toBinaryString(xor1); String t = Integer.toBinaryString(xor2); int cnt = (1<< Math.max(t.length(), s.length())); int ans = cnt; xor1 += cnt; xor2 += cnt; s = Integer.toBinaryString(xor1); t = Integer.toBinaryString(xor2); // System.out.println(s+" "+t); int i = s.length()-1; int j = t.length()-1; while(i>=0 && j>=0) { if(s.charAt(i)!=t.charAt(j)) { ans += (1<<s.length()-i-1); } i--; j--; } a[n-2] = cnt; a[n-1] = ans; for(int k : a) { res.append(k+" "); } res.append("\n"); } } System.out.println(res); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
d01e317c802b06f6ec7f0cc142c3a302
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main { private static final void solve() throws IOException { int n = ni(); var a = new int[n]; for (int i = 1; i < n; i++) a[0] ^= a[i] = i; a[0] ^= 1 << 20; a[1] ^= 1 << 20; a[0] ^= 1 << 21; a[2] ^= 1 << 21; ou.print(a); return; } public static void main(String[] args) throws IOException { for (int i = 0, t = ni(); i < t; i++) solve(); ou.flush(); } private static final int ni() throws IOException { return sc.nextInt(); } private static final int[] ni(int n) throws IOException { return sc.nextIntArray(n); } private static final long nl() throws IOException { return sc.nextLong(); } private static final long[] nl(int n) throws IOException { return sc.nextLongArray(n); } private static final String ns() throws IOException { return sc.next(); } private static final ContestInputStream sc = new ContestInputStream(); private static final ContestOutputStream ou = new ContestOutputStream(); } final class StringAlgorithm { private static int[] saNaive(int[] s) { int n = s.length; int[] sa = new int[n]; for (int i = 0; i < n; i++) { sa[i] = i; } insertionsortUsingComparator(sa, (l, r) -> { while (l < n && r < n) { if (s[l] != s[r]) return s[l] - s[r]; l++; r++; } return -(l - r); }); return sa; } private static int[] saDoubling(int[] s) { int n = s.length; int[] sa = new int[n]; for (int i = 0; i < n; i++) { sa[i] = i; } int[] rnk = java.util.Arrays.copyOf(s, n); int[] tmp = new int[n]; for (int k = 1; k < n; k *= 2) { final int _k = k; final int[] _rnk = rnk; java.util.function.IntBinaryOperator cmp = (x, y) -> { if (_rnk[x] != _rnk[y]) return _rnk[x] - _rnk[y]; int rx = x + _k < n ? _rnk[x + _k] : -1; int ry = y + _k < n ? _rnk[y + _k] : -1; return rx - ry; }; mergesortUsingComparator(sa, cmp); tmp[sa[0]] = 0; for (int i = 1; i < n; i++) { tmp[sa[i]] = tmp[sa[i - 1]] + (cmp.applyAsInt(sa[i - 1], sa[i]) < 0 ? 1 : 0); } int[] buf = tmp; tmp = rnk; rnk = buf; } return sa; } private static void insertionsortUsingComparator(int[] a, java.util.function.IntBinaryOperator comparator) { final int n = a.length; for (int i = 1; i < n; i++) { final int tmp = a[i]; if (comparator.applyAsInt(a[i - 1], tmp) > 0) { int j = i; do { a[j] = a[j - 1]; j--; } while (j > 0 && comparator.applyAsInt(a[j - 1], tmp) > 0); a[j] = tmp; } } } private static void mergesortUsingComparator(int[] a, java.util.function.IntBinaryOperator comparator) { final int n = a.length; final int[] work = new int[n]; for (int block = 1; block <= n; block <<= 1) { final int block2 = block << 1; for (int l = 0, max = n - block; l < max; l += block2) { int m = l + block; int r = Math.min(l + block2, n); System.arraycopy(a, l, work, 0, block); for (int i = l, wi = 0, ti = m;; i++) { if (ti == r) { System.arraycopy(work, wi, a, i, block - wi); break; } if (comparator.applyAsInt(work[wi], a[ti]) > 0) { a[i] = a[ti++]; } else { a[i] = work[wi++]; if (wi == block) break; } } } } } private static final int THRESHOLD_NAIVE = 50; private static final int THRESHOLD_DOUBLING = 0; private static int[] sais(int[] s, int upper) { int n = s.length; if (n == 0) return new int[0]; if (n == 1) return new int[] { 0 }; if (n == 2) { if (s[0] < s[1]) { return new int[] { 0, 1 }; } else { return new int[] { 1, 0 }; } } if (n < THRESHOLD_NAIVE) { return saNaive(s); } // if (n < THRESHOLD_DOUBLING) { // return saDoubling(s); // } int[] sa = new int[n]; boolean[] ls = new boolean[n]; for (int i = n - 2; i >= 0; i--) { ls[i] = s[i] == s[i + 1] ? ls[i + 1] : s[i] < s[i + 1]; } int[] sumL = new int[upper + 1]; int[] sumS = new int[upper + 1]; for (int i = 0; i < n; i++) { if (ls[i]) { sumL[s[i] + 1]++; } else { sumS[s[i]]++; } } for (int i = 0; i <= upper; i++) { sumS[i] += sumL[i]; if (i < upper) sumL[i + 1] += sumS[i]; } java.util.function.Consumer<int[]> induce = lms -> { java.util.Arrays.fill(sa, -1); int[] buf = new int[upper + 1]; System.arraycopy(sumS, 0, buf, 0, upper + 1); for (int d : lms) { if (d == n) continue; sa[buf[s[d]]++] = d; } System.arraycopy(sumL, 0, buf, 0, upper + 1); sa[buf[s[n - 1]]++] = n - 1; for (int i = 0; i < n; i++) { int v = sa[i]; if (v >= 1 && !ls[v - 1]) { sa[buf[s[v - 1]]++] = v - 1; } } System.arraycopy(sumL, 0, buf, 0, upper + 1); for (int i = n - 1; i >= 0; i--) { int v = sa[i]; if (v >= 1 && ls[v - 1]) { sa[--buf[s[v - 1] + 1]] = v - 1; } } }; int[] lmsMap = new int[n + 1]; java.util.Arrays.fill(lmsMap, -1); int m = 0; for (int i = 1; i < n; i++) { if (!ls[i - 1] && ls[i]) { lmsMap[i] = m++; } } int[] lms = new int[m]; { int p = 0; for (int i = 1; i < n; i++) { if (!ls[i - 1] && ls[i]) { lms[p++] = i; } } } induce.accept(lms); if (m > 0) { int[] sortedLms = new int[m]; { int p = 0; for (int v : sa) { if (lmsMap[v] != -1) { sortedLms[p++] = v; } } } int[] recS = new int[m]; int recUpper = 0; recS[lmsMap[sortedLms[0]]] = 0; for (int i = 1; i < m; i++) { int l = sortedLms[i - 1], r = sortedLms[i]; int endL = (lmsMap[l] + 1 < m) ? lms[lmsMap[l] + 1] : n; int endR = (lmsMap[r] + 1 < m) ? lms[lmsMap[r] + 1] : n; boolean same = true; if (endL - l != endR - r) { same = false; } else { while (l < endL && s[l] == s[r]) { l++; r++; } if (l == n || s[l] != s[r]) same = false; } if (!same) { recUpper++; } recS[lmsMap[sortedLms[i]]] = recUpper; } int[] recSA = sais(recS, recUpper); for (int i = 0; i < m; i++) { sortedLms[i] = lms[recSA[i]]; } induce.accept(sortedLms); } return sa; } public static int[] suffixArray(int[] s, int upper) { assert (0 <= upper); for (int d : s) { assert (0 <= d && d <= upper); } return sais(s, upper); } public static int[] suffixArray(int[] s) { int n = s.length; int[] vals = Arrays.copyOf(s, n); java.util.Arrays.sort(vals); int p = 1; for (int i = 1; i < n; i++) { if (vals[i] != vals[i - 1]) { vals[p++] = vals[i]; } } int[] s2 = new int[n]; for (int i = 0; i < n; i++) { s2[i] = java.util.Arrays.binarySearch(vals, 0, p, s[i]); } return sais(s2, p); } public static int[] suffixArray(char[] s) { int n = s.length; int[] s2 = new int[n]; for (int i = 0; i < n; i++) { s2[i] = s[i]; } return sais(s2, 255); } public static int[] suffixArray(java.lang.String s) { return suffixArray(s.toCharArray()); } public static int[] lcpArray(int[] s, int[] sa) { int n = s.length; assert (n >= 1); int[] rnk = new int[n]; for (int i = 0; i < n; i++) { rnk[sa[i]] = i; } int[] lcp = new int[n - 1]; int h = 0; for (int i = 0; i < n; i++) { if (h > 0) h--; if (rnk[i] == 0) { continue; } int j = sa[rnk[i] - 1]; for (; j + h < n && i + h < n; h++) { if (s[j + h] != s[i + h]) break; } lcp[rnk[i] - 1] = h; } return lcp; } public static int[] lcpArray(char[] s, int[] sa) { int n = s.length; int[] s2 = new int[n]; for (int i = 0; i < n; i++) { s2[i] = s[i]; } return lcpArray(s2, sa); } public static int[] lcpArray(java.lang.String s, int[] sa) { return lcpArray(s.toCharArray(), sa); } public static int[] zAlgorithm(int[] s) { int n = s.length; if (n == 0) return new int[0]; int[] z = new int[n]; for (int i = 1, j = 0; i < n; i++) { int k = j + z[j] <= i ? 0 : Math.min(j + z[j] - i, z[i - j]); while (i + k < n && s[k] == s[i + k]) k++; z[i] = k; if (j + z[j] < i + z[i]) j = i; } z[0] = n; return z; } public static int[] zAlgorithm(char[] s) { int n = s.length; if (n == 0) return new int[0]; int[] z = new int[n]; for (int i = 1, j = 0; i < n; i++) { int k = j + z[j] <= i ? 0 : Math.min(j + z[j] - i, z[i - j]); while (i + k < n && s[k] == s[i + k]) k++; z[i] = k; if (j + z[j] < i + z[i]) j = i; } z[0] = n; return z; } public static int[] zAlgorithm(String s) { return zAlgorithm(s.toCharArray()); } } final class ContestInputStream extends FilterInputStream { protected final byte[] buf; protected int pos = 0; protected int lim = 0; private final char[] cbuf; public ContestInputStream() { super(System.in); this.buf = new byte[1 << 13]; this.cbuf = new char[1 << 20]; } boolean hasRemaining() throws IOException { if (pos < lim) return true; lim = in.read(buf); pos = 0; return lim > 0; } final int remaining() throws IOException { if (pos >= lim) { lim = in.read(buf); pos = 0; } return lim - pos; } @Override public final int available() throws IOException { if (pos < lim) return lim - pos + in.available(); return in.available(); } @Override public final long skip(long n) throws IOException { if (pos < lim) { int rem = lim - pos; if (n < rem) { pos += n; return n; } pos = lim; return rem; } return in.skip(n); } @Override public final int read() throws IOException { if (hasRemaining()) return buf[pos++]; return -1; } @Override public final int read(byte[] b, int off, int len) throws IOException { if (pos < lim) { int rem = Math.min(lim - pos, len); for (int i = 0; i < rem; i++) b[off + i] = buf[pos + i]; pos += rem; return rem; } return in.read(b, off, len); } public final char[] readToken() throws IOException { int cpos = 0; int rem; byte b; l: while ((rem = remaining()) > 0) { for (int i = 0; i < rem; i++) { b = buf[pos + i]; if (b <= 0x20) { pos += i + 1; cpos += i; if (b == 0x0d && hasRemaining() && buf[pos] == 0x0a) pos++; break l; } cbuf[cpos + i] = (char) b; } pos += rem; cpos += rem; } char[] arr = new char[cpos]; for (int i = 0; i < cpos; i++) arr[i] = cbuf[i]; return arr; } public final int readToken(char[] cbuf, int off) throws IOException { int cpos = off; int rem; byte b; l: while ((rem = remaining()) > 0) { for (int i = 0; i < rem; i++) { b = buf[pos + i]; if (b <= 0x20) { pos += i + 1; cpos += i; if (b == 0x0d && hasRemaining() && buf[pos] == 0x0a) pos++; break l; } cbuf[cpos + i] = (char) b; } pos += rem; cpos += rem; } return cpos - off; } public final int readToken(char[] cbuf) throws IOException { return readToken(cbuf, 0); } public final String next() throws IOException { int cpos = 0; int rem; byte b; l: while ((rem = remaining()) > 0) { for (int i = 0; i < rem; i++) { b = buf[pos + i]; if (b <= 0x20) { pos += i + 1; cpos += i; if (b == 0x0d && hasRemaining() && buf[pos] == 0x0a) pos++; break l; } cbuf[cpos + i] = (char) b; } pos += rem; cpos += rem; } return String.valueOf(cbuf, 0, cpos); } public final char[] nextCharArray() throws IOException { return readToken(); } public final int nextInt() throws IOException { if (!hasRemaining()) return 0; int value = 0; byte b = buf[pos++]; if (b == 0x2d) { while (hasRemaining() && (b = buf[pos++]) > 0x20) value = value * 10 - b + 0x30; } else { do { value = value * 10 + b - 0x30; } while (hasRemaining() && (b = buf[pos++]) > 0x20); } if (b == 0x0d && hasRemaining() && buf[pos] == 0x0a) pos++; return value; } public final long nextLong() throws IOException { if (!hasRemaining()) return 0L; long value = 0L; byte b = buf[pos++]; if (b == 0x2d) { while (hasRemaining() && (b = buf[pos++]) > 0x20) value = value * 10 - b + 0x30; } else { do { value = value * 10 + b - 0x30; } while (hasRemaining() && (b = buf[pos++]) > 0x20); } if (b == 0x0d && hasRemaining() && buf[pos] == 0x0a) pos++; return value; } public final char nextChar() throws IOException { if (!hasRemaining()) throw new EOFException(); final char c = (char) buf[pos++]; if (hasRemaining() && buf[pos++] == 0x0d && hasRemaining() && buf[pos] == 0x0a) pos++; return c; } public final float nextFloat() throws IOException { return Float.parseFloat(next()); } public final double nextDouble() throws IOException { return Double.parseDouble(next()); } public final boolean[] nextBooleanArray(char ok) throws IOException { char[] s = readToken(); int n = s.length; boolean[] t = new boolean[n]; for (int i = 0; i < n; i++) t[i] = s[i] == ok; return t; } public final boolean[][] nextBooleanMatrix(int h, int w, char ok) throws IOException { boolean[][] s = new boolean[h][]; for (int i = 0; i < h; i++) { char[] t = readToken(); int n = t.length; s[i] = new boolean[n]; for (int j = 0; j < n; j++) s[i][j] = t[j] == ok; } return s; } public final String[] nextStringArray(int len) throws IOException { String[] arr = new String[len]; for (int i = 0; i < len; i++) arr[i] = next(); return arr; } public final int[] nextIntArray(int len) throws IOException { int[] arr = new int[len]; for (int i = 0; i < len; i++) arr[i] = nextInt(); return arr; } public final int[] nextIntArray(int len, java.util.function.IntUnaryOperator map) throws IOException { int[] arr = new int[len]; for (int i = 0; i < len; i++) arr[i] = map.applyAsInt(nextInt()); return arr; } public final long[] nextLongArray(int len, java.util.function.LongUnaryOperator map) throws IOException { long[] arr = new long[len]; for (int i = 0; i < len; i++) arr[i] = map.applyAsLong(nextLong()); return arr; } public final int[][] nextIntMatrix(int h, int w) throws IOException { int[][] arr = new int[h][w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) arr[i][j] = nextInt(); return arr; } public final int[][] nextIntMatrix(int h, int w, java.util.function.IntUnaryOperator map) throws IOException { int[][] arr = new int[h][w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) arr[i][j] = map.applyAsInt(nextInt()); return arr; } public final long[] nextLongArray(int len) throws IOException { long[] arr = new long[len]; for (int i = 0; i < len; i++) arr[i] = nextLong(); return arr; } public final long[][] nextLongMatrix(int h, int w) throws IOException { long[][] arr = new long[h][w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) arr[i][j] = nextLong(); return arr; } public final float[] nextFloatArray(int len) throws IOException { float[] arr = new float[len]; for (int i = 0; i < len; i++) arr[i] = nextFloat(); return arr; } public final double[] nextDoubleArray(int len) throws IOException { double[] arr = new double[len]; for (int i = 0; i < len; i++) arr[i] = nextDouble(); return arr; } public final char[][] nextCharMatrix(int h, int w) throws IOException { char[][] arr = new char[h][]; for (int i = 0; i < h; i++) arr[i] = readToken(); return arr; } public final void nextThrow() throws IOException { next(); return; } public final void nextThrow(int n) throws IOException { for (int i = 0; i < n; i++) nextThrow(); return; } } final class ContestOutputStream extends FilterOutputStream implements Appendable { protected final byte[] buf; protected int pos = 0; public ContestOutputStream() { super(System.out); this.buf = new byte[1 << 13]; } @Override public void flush() throws IOException { out.write(buf, 0, pos); pos = 0; out.flush(); } void put(byte b) throws IOException { if (pos >= buf.length) flush(); buf[pos++] = b; } int remaining() throws IOException { if (pos >= buf.length) flush(); return buf.length - pos; } @Override public void write(int b) throws IOException { put((byte) b); } @Override public void write(byte[] b, int off, int len) throws IOException { int o = off; int l = len; while (l > 0) { int rem = Math.min(remaining(), l); for (int i = 0; i < rem; i++) buf[pos + i] = b[o + i]; pos += rem; o += rem; l -= rem; } } @Override public ContestOutputStream append(char c) throws IOException { put((byte) c); return this; } @Override public ContestOutputStream append(CharSequence csq, int start, int end) throws IOException { int off = start; int len = end - start; while (len > 0) { int rem = Math.min(remaining(), len); for (int i = 0; i < rem; i++) buf[pos + i] = (byte) csq.charAt(off + i); pos += rem; off += rem; len -= rem; } return this; } @Override public ContestOutputStream append(CharSequence csq) throws IOException { return append(csq, 0, csq.length()); } public ContestOutputStream append(char[] arr, int off, int len) throws IOException { int o = off; int l = len; while (l > 0) { int rem = Math.min(remaining(), l); for (int i = 0; i < rem; i++) buf[pos + i] = (byte) arr[o + i]; pos += rem; o += rem; l -= rem; } return this; } public ContestOutputStream print(char[] arr) throws IOException { return append(arr, 0, arr.length).newLine(); } public ContestOutputStream print(boolean value) throws IOException { if (value) return append("o"); return append("x"); } public ContestOutputStream println(boolean value) throws IOException { if (value) return append("o\n"); return append("x\n"); } public ContestOutputStream print(boolean[][] value) throws IOException { final int n = value.length, m = value[0].length; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) print(value[i][j]); newLine(); } return this; } public ContestOutputStream print(int value) throws IOException { return append(String.valueOf(value)); } public ContestOutputStream println(int value) throws IOException { return append(String.valueOf(value)).newLine(); } public ContestOutputStream print(long value) throws IOException { return append(String.valueOf(value)); } public ContestOutputStream println(long value) throws IOException { return append(String.valueOf(value)).newLine(); } public ContestOutputStream print(float value) throws IOException { return append(String.valueOf(value)); } public ContestOutputStream println(float value) throws IOException { return append(String.valueOf(value)).newLine(); } public ContestOutputStream print(double value) throws IOException { return append(String.valueOf(value)); } public ContestOutputStream println(double value) throws IOException { return append(String.valueOf(value)).newLine(); } public ContestOutputStream print(char value) throws IOException { return append(value); } public ContestOutputStream println(char value) throws IOException { return append(value).newLine(); } public ContestOutputStream print(String value) throws IOException { return append(value); } public ContestOutputStream println(String value) throws IOException { return append(String.valueOf(value)).newLine(); } public ContestOutputStream print(Object value) throws IOException { return append(String.valueOf(value)); } public ContestOutputStream println(Object value) throws IOException { return append(String.valueOf(value)).newLine(); } public ContestOutputStream printYN(boolean yes) throws IOException { if (yes) return println("Yes"); return println("No"); } public ContestOutputStream printAB(boolean yes) throws IOException { if (yes) return println("Alice"); return println("Bob"); } public ContestOutputStream print(CharSequence[] arr) throws IOException { if (arr.length > 0) { append(arr[0]); for (int i = 1; i < arr.length; i++) append('\u0020').append(arr[i]); } return this; } public ContestOutputStream print(int[] arr) throws IOException { if (arr.length > 0) { print(arr[0]); for (int i = 1; i < arr.length; i++) append('\u0020').print(arr[i]); } newLine(); return this; } public ContestOutputStream print(int[] arr, int length) throws IOException { if (length > 0) print(arr[0]); for (int i = 1; i < length; i++) append('\u0020').print(arr[i]); newLine(); return this; } public ContestOutputStream println(int[] arr) throws IOException { for (int i : arr) print(i).newLine(); return this; } public ContestOutputStream println(int[] arr, int length) throws IOException { for (int i = 0; i < length; i++) println(arr[i]); return this; } public ContestOutputStream print(boolean[] arr) throws IOException { if (arr.length > 0) { print(arr[0]); for (int i = 1; i < arr.length; i++) append('\u0020').print(arr[i]); } newLine(); return this; } public ContestOutputStream print(long[] arr) throws IOException { if (arr.length > 0) { print(arr[0]); for (int i = 1; i < arr.length; i++) append('\u0020').print(arr[i]); } newLine(); return this; } public ContestOutputStream print(long[] arr, int length) throws IOException { if (length > 0) print(arr[0]); for (int i = 1; i < length; i++) append('\u0020').print(arr[i]); newLine(); return this; } public ContestOutputStream println(long[] arr, int length) throws IOException { for (int i = 0; i < length; i++) println(arr[i]); return this; } public ContestOutputStream println(long[] arr) throws IOException { for (long i : arr) print(i).newLine(); return this; } public ContestOutputStream print(float[] arr) throws IOException { if (arr.length > 0) { print(arr[0]); for (int i = 1; i < arr.length; i++) append('\u0020').print(arr[i]); } return this; } public ContestOutputStream println(float[] arr) throws IOException { for (float i : arr) print(i).newLine(); return this; } public ContestOutputStream print(double[] arr) throws IOException { if (arr.length > 0) { print(arr[0]); for (int i = 1; i < arr.length; i++) append('\u0020').print(arr[i]); } return newLine(); } public ContestOutputStream println(double[] arr) throws IOException { for (double i : arr) print(i).newLine(); return this; } public ContestOutputStream print(Object[] arr) throws IOException { if (arr.length > 0) { print(arr[0]); for (int i = 1; i < arr.length; i++) append('\u0020').print(arr[i]); } return newLine(); } public ContestOutputStream print(java.util.ArrayList<?> arr) throws IOException { if (!arr.isEmpty()) { final int n = arr.size(); print(arr.get(0)); for (int i = 1; i < n; i++) print(" ").print(arr.get(i)); } return newLine(); } public ContestOutputStream println(java.util.ArrayList<?> arr) throws IOException { final int n = arr.size(); for (int i = 0; i < n; i++) println(arr.get(i)); return this; } public ContestOutputStream println(Object[] arr) throws IOException { for (Object i : arr) print(i).newLine(); return this; } public ContestOutputStream newLine() throws IOException { return append(System.lineSeparator()); } public ContestOutputStream endl() throws IOException { newLine().flush(); return this; } public ContestOutputStream print(int[][] arr) throws IOException { for (int[] i : arr) print(i); return this; } public ContestOutputStream print(long[][] arr) throws IOException { for (long[] i : arr) print(i); return this; } public ContestOutputStream print(char[][] arr) throws IOException { for (char[] i : arr) print(i); return this; } public ContestOutputStream print(Object[][] arr) throws IOException { for (Object[] i : arr) print(i); return this; } public ContestOutputStream println() throws IOException { return newLine(); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
27b42341ef531d3f07f08ad0ad792664
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static Scanner obj = new Scanner(System.in); public static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int len = obj.nextInt(); while (len-- != 0) { int n=obj.nextInt(); long[] a=new long[n+1]; for(int i=1;i<=n-3;i++)a[i]=i; a[n-2]=(long)(1L<<26L); a[n-1]=(long)(1L<<27L); long a1=0,a2=0; for(int i=1;i<=n;i++) { if(i%2==0)a1=a1^a[i]; else a2=a2^a[i]; } a[n]=a1^a2; a1=0; a2=0; for(int i=1;i<=n;i++) { out.print(a[i]+" "); } out.println(); } out.flush(); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
f636eec9b9523d059cc366415ac4e729
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; //import org.graalvm.compiler.core.common.Fields.ObjectTransformer; import java.math.*; import java.math.BigInteger; public final class A { static PrintWriter out = new PrintWriter(System.out); static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); static ArrayList<pair> g[]; static long mod=(long)(1e9+7),INF=Long.MAX_VALUE; static boolean set[]; static long max=0; static int lca[][]; static int par[],col[],D[]; static long fact[]; static int size[],dp[],countW[],countB[],N; static long sum[],f[]; static long t[],max_depth[],seg[]; static boolean sep[],isWhite[]; static boolean marked[],visited[],recStack[]; static int segR[],segC[]; static HashMap<Integer,Integer> mp[]; public static void main(String args[])throws IOException { /* * star,rope,TPST,preX * BS,LST,MS,MQ */ int T=i(); while(T-->0) { int N=i(); int a=0; int max=1<<30; for(int i=1; i<N; i++) { a^=i; } boolean f=true; out.print((max+a)+" "); for(int i=1; i<N; i++) { if(f && i!=a) { out.print((i+max)+" "); f=false; } else out.print(i+" "); } out.println(); } out.println(ans); out.close(); } static long f(long A[],long B[],long p) { long ans=0; int N=A.length; boolean setA[]=new boolean[N],setB[]=new boolean[N]; while(p>=1) { int a=0,b=0; for(int i=0; i<A.length; i++) { boolean x=((A[i]&p)!=0),y=((B[i]&p)!=0); if(x)a++; if(y)b++; if(set[i] && set[i]) { p>>=1; continue; } //5 5 1 1 } int c=a+b; if(c==A.length) { //now freq is n and they don't conflict as well } } return ans; } static boolean f(int A[],int m) { int N=A.length; int X[]=new int[N]; int j=0; for(int i=1; i<m; i+=2) { X[i]=j++; } return m<=0; } static int[] f(int N,int M,int A[][]) { int Q=A.length; int X[]=new int[M]; par=new int[N+1]; Arrays.fill(par, -1); for(int i=0;i<Q; i++) { int c=A[i][0],a=A[i][1],b=A[i][2]; if(c==1) { //a eats x par[find(a)]--; } else { int x=find(a),y=find(b); if(par[x]<par[y]) union(x,y); else union(y,x); } } for(int i=0;i<Q; i++) { int c=A[i][0],a=A[i][1],b=A[i][2]; if(c==1) { int p=find(a); X[b-1]=p; } } return X; } public static int f(int i,long A[],int next[]) { if(i>=A.length)return 0; if(dp[i]==-1) { if(A[i]==0) { dp[i]=f(i+1,A,next); } else { dp[i]=Math.min(1+f(i+1,A,next), next[i]-i+f(next[i]+1,A,next)); } } return dp[i]; } public static int f1(String text) { char X[]=text.toCharArray(); int N=X.length; int f[]=new int[26]; for(char x:X)f[x-'a']++; int s=0; int m=1; Arrays.sort(f); // print(f); for(int a=25; a>=0; a-- ) { int i=f[a]; if(i!=0) { if(m<=9) s+=i; else if(m<=18)s+=(2*i); else s+=(3*i); m++; } } return s; } static int f(int A[][]) { int c=0; int N=A.length,M=A[0].length; int col[]=new int[M],row[]=new int[N]; for(int i=0; i<N; i++) { for(int j=0; j<M; j++) { if(A[i][j]==1) { col[j]++; row[i]++; } } } for(int i=0; i<N; i++) { for(int j=0; j<M; j++) { int tot=N+M-1; c=Math.max(c, (col[j]+row[i])*2-tot); } } return c; } static int ttt=0; static int ask(int a,int b) { out.println("? "+a+" "+b); // out.println(); ttt++; out.flush(); return i(); } static int f(int l,int r,int A[]) { if(l==r) { return A[1]; } if(r-l==1) { int a=ask(A[l],A[r]); if(a==1)return A[l]; else return A[r]; } else { int j=0; for(int i=1; i<=r; i+=4) { int a=ask(A[i],A[i+2]); if(a==0) { a=ask(A[i+1],A[i+3]); if(a==1)A[++j]=A[i+1]; else A[++j]=A[i+3]; } else if(a==1) { // A[++j]=ask(A[i],A[i+3]); a=ask(A[i],A[i+3]); if(a==1)A[++j]=A[i]; else A[++j]=A[i+3]; } else { // A[++j]=ask(A[i+1],A[i+2]); a=ask(A[i+1],A[i+2]); if(a==1)A[++j]=A[i+1]; else A[++j]=A[i+2]; } } r=j; return f(l,r,A); } } static void calculatePre(long A[][],int N,int M) { for(int i=1; i<=N; i++) { for(int j=1; j<=M; j++)A[i][j]+=A[i][j-1]; } for(int j=1; j<=M; j++) { for(int i=2; i<=N; i++)A[i][j]+=A[i-1][j]; } } static boolean equals(char X[],char Y[]) { for(int i=0; i<X.length; i++)if(X[i]!=Y[i])return false; return true; } static long nCr(long n,long r) { long s=0; long c=n-r; n=fact[(int)n]; r=fact[(int)r]; c=fact[(int)c]; r=pow(r,mod-2)%mod; c=pow(c,mod-2)%mod; s=(r*c)%mod; s=(s*n)%mod; return s%mod; } static boolean isValid(int x,int y,int N,int M) { if(x>=N || y>=M)return false; if(x<0 || y<0)return false; return true; } static boolean isPower(long a,long b) { while(a%b==0) { } return a==1; } static String rotate(String X,int K) { StringBuilder sb=new StringBuilder(); int N=X.length(); int k=K%N; for(int i=N-k; i<N;i++) { sb.append(X.charAt(i)); } for(int i=0; i<N-k; i++) { sb.append(X.charAt(i)); } return sb.toString(); } static int rounds(String X,String Y) { int n=Y.length(); for(int i=1; i<Y.length(); i++) { if(X.charAt(0)==Y.charAt(0) && X.substring(i,i+n).equals(Y))return i; } return Y.length(); } static int index(ArrayList<Long> X,long x) { int l=-1,r=X.size(); while(r-l>1) { int m=(l+r)/2; if(X.get(m)<=x)l=m; else r=m; } return l+1; } static void swap(int i,int j,long A[][]) { for(int row=0; row<A.length; row++) { long t=A[row][i]; A[row][i]=A[row][j]; A[row][j]=t; } } static boolean isSorted(long A[]) { for(int i=1; i<A.length; i++)if(A[i]<A[i-1])return false; return true; } static void push(int v) { if (marked[v]) { t[v*2] = t[v*2+1] = t[v]; marked[v*2] = marked[v*2+1] = true; marked[v] = false; } } static void update1(int v, int tl, int tr, int l, int r, int new_val) { if (l > r) return; if (l == tl && tr == r) { t[v] = new_val; marked[v] = true; } else { push(v); int tm = (tl + tr) / 2; update1(v*2, tl, tm, l, Math.min(r, tm), new_val); update1(v*2+1, tm+1, tr, Math.max(l, tm+1), r, new_val); } } static long get1(int v, int tl, int tr, int pos) { if (tl == tr) { return t[v]; } push(v); int tm = (tl + tr) / 2; if (pos <= tm) return get1(v*2, tl, tm, pos); else return get1(v*2+1, tm+1, tr, pos); } static int cost=0; static void fmin(int i,int j,ArrayList<Integer> A,int cZ,int cO) { if(j-i>1) { int a=A.get(i),b=A.get(j); cO+=Math.min(a, b); if(a<b) { } else if(b>a) { } else { } } } static int f(char X[],char Y[]) { int s=0; for(int i=0; i<Y.length; i++) { s+=Math.abs(X[i]-Y[i]); } return s; } public static long mergeSort(int A[],int l,int r) { long a=0; if(l<r) { int m=(l+r)/2; a+=mergeSort(A,l,m); a+=mergeSort(A,m+1,r); a+=merge(A,l,m,r); } return a; } public static long merge(int A[],int l,int m,int r) { long a=0; int i=l,j=m+1,index=0; long c=0; int B[]=new int[r-l+1]; while(i<=m && j<=r) { if(A[i]<=A[j]) { c++; B[index++]=A[i++]; } else { long s=(m-l)+1; a+=(s-c); B[index++]=A[j++]; } } while(i<=m)B[index++]=A[i++]; while(j<=r)B[index++]=A[j++]; index=0; for(; l<=r; l++)A[l]=B[index++]; return a; } static int f(int A[]) { int s=0; for(int i=1; i<4; i++) { s+=Math.abs(A[i]-A[i-1]); } return s; } static boolean f(int A[],int B[],int N) { for(int i=0; i<N; i++) { if(Math.abs(A[i]-B[i])>1)return false; } return true; } static int [] prefix(char s[],int N) { // int n = (int)s.length(); // vector<int> pi(n); N=s.length; int pi[]=new int[N]; for (int i = 1; i < N; i++) { int j = pi[i-1]; while (j > 0 && s[i] != s[j]) j = pi[j-1]; if (s[i] == s[j]) j++; pi[i] = j; } return pi; } static int count(long N) { int cnt=0; long p=1L; while(p<=N) { if((p&N)!=0)cnt++; p<<=1; } return cnt; } static long kadane(long A[]) { long lsum=A[0],gsum=0; gsum=Math.max(gsum, lsum); for(int i=1; i<A.length; i++) { lsum=Math.max(lsum+A[i],A[i]); gsum=Math.max(gsum,lsum); } return gsum; } public static void reverse(int i,int j,int A[]) { while(i<j) { int t=A[i]; A[i]=A[j]; A[j]=t; i++; j--; } } public static int ask(int a,int b,int c) { System.out.println("? "+a+" "+b+" "+c); return i(); } static int[] reverse(int A[],int N) { int B[]=new int[N]; for(int i=N-1; i>=0; i--) { B[N-i-1]=A[i]; } return B; } static boolean isPalin(char X[]) { int i=0,j=X.length-1; while(i<=j) { if(X[i]!=X[j])return false; i++; j--; } return true; } static int distance(int a,int b) { int d=D[a]+D[b]; int l=LCA(a,b); l=2*D[l]; return d-l; } static int LCA(int a,int b) { if(D[a]<D[b]) { int t=a; a=b; b=t; } int d=D[a]-D[b]; int p=1; for(int i=0; i>=0 && p<=d; i++) { if((p&d)!=0) { a=lca[a][i]; } p<<=1; } if(a==b)return a; for(int i=(int)(max-1); i>=0; i--) { if(lca[a][i]!=-1 && lca[a][i]!=lca[b][i]) { a=lca[a][i]; b=lca[b][i]; } } return lca[a][0]; } static int[] prefix_function(char X[])//returns pi(i) array { int N=X.length; int pre[]=new int[N]; for(int i=1; i<N; i++) { int j=pre[i-1]; while(j>0 && X[i]!=X[j]) j=pre[j-1]; if(X[i]==X[j])j++; pre[i]=j; } return pre; } static int right(int A[],int Limit,int l,int r) { while(r-l>1) { int m=(l+r)/2; if(A[m]<Limit)l=m; else r=m; } return l; } static int left(int A[],int a,int l,int r) { while(r-l>1) { int m=(l+r)/2; if(A[m]<a)l=m; else r=m; } return l; } // static void build(int v,int tl,int tr,long A[]) // { // if(tl==tr) // { // long a=0; // if(A[tl]>0) // { // a=A[tl]; // // } // seg[v]=new node(a,a,a,A[tl],A[tl]); // return; // } // int tm=(tl+tr)/2; // build(v*2,tl,tm,A); // build(v*2+1,tm+1,tr,A); // seg[v]=combine(seg[v*2],seg[v*2+1]); // } // static node combine(node a,node b) // { // node temp=new node(0,0,0,0); // temp.pref=max(a.pref,a.sum+b.pref,a.sum+b.sum); // temp.suff=max(b.suff,b.sum+a.suff,b.sum+a.sum); // temp.max=max(a.max,b.max,a.suff+b.pref); // temp.sum=a.sum+b.sum; // temp.min=Math.max(a.min, b.min); // return temp; // } // static long max(long a,long b,long c) // { // return Math.max(a,Math.max(b, c)); // } // // static void update(int v,int tl,int tr,int index) // // { // // if(index==tl && index==tr) // // { // // segR[v]+=1; // // segR[v]%=2; // // } // // else // // { // // int tm=(tl+tr)/2; // // if(index<=tm)update(v*2,tl,tm,index); // // else update(v*2+1,tm+1,tr,index); // // segR[v]=segR[v*2]+segR[v*2+1]; // // } // // } // static long ask(int v,int tl,int tr,int l,int r) // { // // if(l>r)return 0; // if(tl==l && r==tr) // { // return seg[v].max; // } // int tm=(tl+tr)/2; // // return Math.max(ask(v*2,tl,tm,l,Math.min(tm, r)),ask(v*2+1,tm+1,tr,Math.max(tm+1, l),r)); // } static void build(int v,int tl,int tr,long A[]) { if(tl==tr) { seg[v]=A[tl]; return; } int tm=(tl+tr)/2; build(v*2,tl,tm,A); build(v*2+1,tm+1,tr,A); seg[v]=Math.max(seg[v*2],seg[v*2+1]); } static void update(int v,int tl,int tr,int index,int a) { if(index==tl && tl==tr) { seg[v]++; seg[v]%=2; } else { int tm=(tl+tr)/2; if(index<=tm)update(2*v,tl,tm,index,a); else update(2*v+1,tm+1,tr,index,a); seg[v]=seg[v*2]+seg[v*2+1]; } } static long ask(int v,int tl,int tr,int l,int r) { if(l>r)return 0; if(tl==l && tr==r)return seg[v]; int tm=(tl+tr)/2; return Math.max(ask(v*2,tl,tm,l,Math.min(tm,r)),ask(v*2+1,tm+1,tr,Math.max(l, tm+1),r)); } static void updateC(int v,int tl,int tr,int index) { if(index==tl && index==tr) { segC[v]+=1; segC[v]%=2; } else { int tm=(tl+tr)/2; if(index<=tm)updateC(v*2,tl,tm,index); else updateC(v*2+1,tm+1,tr,index); segC[v]=segC[v*2]+segC[v*2+1]; } } static int askC(int v,int tl,int tr,int l,int r) { if(l>r)return 0; if(tl==l && r==tr) { return segC[v]; } int tm=(tl+tr)/2; return askC(v*2,tl,tm,l,Math.min(tm, r))+askC(v*2+1,tm+1,tr,Math.max(tm+1, l),r); } static boolean f(long A[],long m,int N) { long B[]=new long[N]; for(int i=0; i<N; i++) { B[i]=A[i]; } for(int i=N-1; i>=0; i--) { if(B[i]<m)return false; if(i>=2) { long extra=Math.min(B[i]-m, A[i]); long x=extra/3L; B[i-2]+=2L*x; B[i-1]+=x; } } return true; } static int f(int l,int r,long A[],long x) { while(r-l>1) { int m=(l+r)/2; if(A[m]>=x)l=m; else r=m; } return r; } static boolean f(long m,long H,long A[],int N) { long s=m; for(int i=0; i<N-1;i++) { s+=Math.min(m, A[i+1]-A[i]); } return s>=H; } static long ask(long l,long r) { System.out.println("? "+l+" "+r); return l(); } static long f(long N,long M) { long s=0; if(N%3==0) { N/=3; s=N*M; } else { long b=N%3; N/=3; N++; s=N*M; N--; long a=N*M; if(M%3==0) { M/=3; a+=(b*M); } else { M/=3; M++; a+=(b*M); } s=Math.min(s, a); } return s; } static int ask(StringBuilder sb,int a) { System.out.println(sb+""+a); return i(); } static void swap(char X[],int i,int j) { char x=X[i]; X[i]=X[j]; X[j]=x; } static int min(int a,int b,int c) { return Math.min(Math.min(a, b), c); } static long and(int i,int j) { System.out.println("and "+i+" "+j); return l(); } static long or(int i,int j) { System.out.println("or "+i+" "+j); return l(); } static int len=0,number=0; static void f(char X[],int i,int num,int l) { if(i==X.length) { if(num==0)return; //update our num if(isPrime(num))return; if(l<len) { len=l; number=num; } return; } int a=X[i]-'0'; f(X,i+1,num*10+a,l+1); f(X,i+1,num,l); } static boolean is_Sorted(int A[]) { int N=A.length; for(int i=1; i<=N; i++)if(A[i-1]!=i)return false; return true; } static boolean f(StringBuilder sb,String Y,String order) { StringBuilder res=new StringBuilder(sb.toString()); HashSet<Character> set=new HashSet<>(); for(char ch:order.toCharArray()) { set.add(ch); for(int i=0; i<sb.length(); i++) { char x=sb.charAt(i); if(set.contains(x))continue; res.append(x); } } String str=res.toString(); return str.equals(Y); } static boolean all_Zero(int f[]) { for(int a:f)if(a!=0)return false; return true; } static long form(int a,int l) { long x=0; while(l-->0) { x*=10; x+=a; } return x; } static int count(String X) { HashSet<Integer> set=new HashSet<>(); for(char x:X.toCharArray())set.add(x-'0'); return set.size(); } static int f(long K) { long l=0,r=K; while(r-l>1) { long m=(l+r)/2; if(m*m<K)l=m; else r=m; } return (int)l; } static int [] sub(int A[],int B[]) { int N=A.length; int f[]=new int[N]; for(int i=N-1; i>=0; i--) { if(B[i]<A[i]) { B[i]+=26; B[i-1]-=1; } f[i]=B[i]-A[i]; } for(int i=0; i<N; i++) { if(f[i]%2!=0)f[i+1]+=26; f[i]/=2; } return f; } static int[] f(int N) { char X[]=in.next().toCharArray(); int A[]=new int[N]; for(int i=0; i<N; i++)A[i]=X[i]-'a'; return A; } static int max(int a ,int b,int c,int d) { a=Math.max(a, b); c=Math.max(c,d); return Math.max(a, c); } static int min(int a ,int b,int c,int d) { a=Math.min(a, b); c=Math.min(c,d); return Math.min(a, c); } static HashMap<Integer,Integer> Hash(int A[]) { HashMap<Integer,Integer> mp=new HashMap<>(); for(int a:A) { int f=mp.getOrDefault(a,0)+1; mp.put(a, f); } return mp; } static long mul(long a, long b) { return ( a %mod * 1L * b%mod )%mod; } static void swap(int A[],int a,int b) { int t=A[a]; A[a]=A[b]; A[b]=t; } static int find(int a) { if(par[a]<0)return a; return par[a]=find(par[a]); } static void union(int a,int b) { a=find(a); b=find(b); if(a!=b) { par[a]+=par[b]; par[b]=a; } } static boolean isSorted(int A[]) { for(int i=1; i<A.length; i++) { if(A[i]<A[i-1])return false; } return true; } static boolean isDivisible(StringBuilder X,int i,long num) { long r=0; for(; i<X.length(); i++) { r=r*10+(X.charAt(i)-'0'); r=r%num; } return r==0; } static int lower_Bound(int A[],int low,int high, int x) { if (low > high) if (x >= A[high]) return A[high]; int mid = (low + high) / 2; if (A[mid] == x) return A[mid]; if (mid > 0 && A[mid - 1] <= x && x < A[mid]) return A[mid - 1]; if (x < A[mid]) return lower_Bound( A, low, mid - 1, x); return lower_Bound(A, mid + 1, high, x); } static String f(String A) { String X=""; for(int i=A.length()-1; i>=0; i--) { int c=A.charAt(i)-'0'; X+=(c+1)%2; } return X; } static void sortR(long[] a) //check for long { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); int N=a.length; for (int i=0; i<a.length; i++) a[i]=l.get(N-i-1); } static void sort(long[] a) //check for long { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static String swap(String X,int i,int j) { char ch[]=X.toCharArray(); char a=ch[i]; ch[i]=ch[j]; ch[j]=a; return new String(ch); } static int sD(long n) { if (n % 2 == 0 ) return 2; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0 ) return i; } return (int)n; } // static void setGraph(int N,int nodes) // { //// size=new int[N+1]; // par=new int[N+1]; // col=new int[N+1]; //// g=new int[N+1][]; // D=new int[N+1]; // int deg[]=new int[N+1]; // int A[][]=new int[nodes][2]; // for(int i=0; i<nodes; i++) // { // int a=i(),b=i(); // A[i][0]=a; // A[i][1]=b; // deg[a]++; // deg[b]++; // } // for(int i=0; i<=N; i++) // { // g[i]=new int[deg[i]]; // deg[i]=0; // } // for(int a[]:A) // { // int x=a[0],y=a[1]; // g[x][deg[x]++]=y; // g[y][deg[y]++]=x; // } // } static long pow(long a,long b) { //long mod=1000000007; long pow=1; long x=a; while(b!=0) { if((b&1)!=0)pow=(pow*x)%mod; x=(x*x)%mod; b/=2; } return pow; } static long toggleBits(long x)//one's complement || Toggle bits { int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1; return ((1<<n)-1)^x; } static int countBits(long a) { return (int)(Math.log(a)/Math.log(2)+1); } static long fact(long N) { long n=2; if(N<=1)return 1; else { for(int i=3; i<=N; i++)n=(n*i)%mod; } return n; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static boolean isPrime(long N) { if (N<=1) return false; if (N<=3) return true; if (N%2 == 0 || N%3 == 0) return false; for (int i=5; i*i<=N; i=i+6) if (N%i == 0 || N%(i+2) == 0) return false; return true; } static void print(char A[]) { for(char c:A)System.out.print(c+" "); System.out.println(); } static void print(boolean A[]) { for(boolean c:A)System.out.print(c+" "); System.out.println(); } static void print(int A[]) { for(int a:A)System.out.print(a+" "); System.out.println(); } static void print(long A[]) { for(long i:A)System.out.print(i+ " "); System.out.println(); } static void print(boolean A[][]) { for(boolean a[]:A)print(a); } static void print(long A[][]) { for(long a[]:A)print(a); } static void print(int A[][]) { for(int a[]:A)print(a); } static void print(ArrayList<Integer> A) { for(int a:A)System.out.print(a+" "); System.out.println(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i<N; i++) { A[i]=in.nextInt(); } return A; } static long[] inputLong(int N) { long A[]=new long[N]; for(int i=0; i<A.length; i++)A[i]=in.nextLong(); return A; } static long GCD(long a,long b) { if(b==0) { return a; } else return GCD(b,a%b ); } } class pair { int a,or; pair(int a,int or) { this.or=or; this.a=a; // size=i; } } //Code For FastReader //Code For FastReader //Code For FastReader //Code For FastReader class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(st==null || !st.hasMoreElements()) { try { st=new StringTokenizer(br.readLine()); } catch(IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } // String nextLine() { String str=""; try { str=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
0e549562881636ce9aa7f1b154107922
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Collections; /* Name of the class has to be "Main" only if the class is public. */ public class G { public static void main (String[] args) throws Exception { // your code goes here FastScanner sc= new FastScanner(); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); if(n%4==0){ for(int i=0;i<n;i++){ System.out.print(i+" "); } }else if(n%4==1){ System.out.print(0+" "); for(int i=0;i<n-1;i++){ System.out.print((i+2)+" "); } }else if(n%4==3){ System.out.print(2+" "+1+" "+3+" "); for(int i=0;i<n-3;i++){ System.out.print((i+4)+" "); } }else{ System.out.print(2+" "+3+" "+1+" "+4+" "+12+" "+8+" "); for(int i=0;i<n-6;i++){ System.out.print((i+14)+" "); } } System.out.println(); } } public static boolean isPrime(long n) { if(n < 2) return false; if(n == 2 || n == 3) return true; if(n%2 == 0 || n%3 == 0) return false; long sqrtN = (long)Math.sqrt(n)+1; for(long i = 6L; i <= sqrtN; i += 6) { if(n%(i-1) == 0 || n%(i+1) == 0) return false; } return true; } public static long gcd(long a, long b) { if(a > b) a = (a+b)-(b=a); if(a == 0L) return b; return gcd(b%a, a); } public static ArrayList<Integer> findDiv(int N) { //gens all divisors of N ArrayList<Integer> ls1 = new ArrayList<Integer>(); ArrayList<Integer> ls2 = new ArrayList<Integer>(); for(int i=1; i <= (int)(Math.sqrt(N)+0.00000001); i++) if(N%i == 0) { ls1.add(i); ls2.add(N/i); } Collections.reverse(ls2); for(int b: ls2) if(b != ls1.get(ls1.size()-1)) ls1.add(b); return ls1; } public static void sort(int[] arr) { //because Arrays.sort() uses quicksort which is dumb //Collections.sort() uses merge sort ArrayList<Integer> ls = new ArrayList<Integer>(); for(int x: arr) ls.add(x); Collections.sort(ls); for(int i=0; i < arr.length; i++) arr[i] = ls.get(i); } public static long power(long x, long y, long p) { //0^0 = 1 long res = 1L; x = x%p; while(y > 0) { if((y&1)==1) res = (res*x)%p; y >>= 1; x = (x*x)%p; } return res; } static class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
3248dee2d1f7f750ce3454c89edf95dc
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
/* KEEP CALM AND जय श्री राम * A B C D are easy just dont give up , you can do it! * FIRST AND VERY IMP -> READ AND UNDERSTAND THE QUESTION VERY CAREFULLY. * WARNING -> DON'T CODE BULLSHIT , ALWAYS CHECK THE LOGIC ON MULTIPLE TESTCASES AND EDGECASES BEFORE. * SECOND -> TRY TO FIND RELEVENT PATTERN SMARTLY. * WARNING -> IF YOU THINK YOUR SOLUION IS JUST DUMB DONT SUBMIT IT BEFORE RECHECKING ON YOUR END. try try till you die; :):):) */ import java.util.*; import java.io.*; import java.util.stream.*; import java.util.Scanner; import java.math.BigInteger; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while (t-- > 0) { long n = scn.nextInt(); long case1 = 0; long case2 = 0; for (int i = 0; i < n - 2; i++) { case1 ^= i; case2 ^= (i + 1); } int addLast = (int)(1 << 31) - 1; if (case1 != 0){ for (int i = 0; i < n - 2; i++){ System.out.print(i+" "); } case1 ^= addLast; System.out.print(addLast); System.out.print(" "); System.out.println(case1); } else{ for (int i = 1; i <= n - 2; i++){ System.out.print(i+" "); } case2 ^= addLast; System.out.print(addLast); System.out.print(" "); System.out.println(case2); } } } public static void print(int k) { System.out.println(k); } public static void printString(String str) { System.out.println(str); } public static void printCharArray(char[] arr) { for (int i = 0 ; i < arr.length ; i++) { System.out.print(arr[i] + " "); } System.out.println(); } // int ko char array m karne ke lia char[] arr = (n+"").toCharArray(); likhneka public static <K, V> K getKey(Map<K, V> map, V value) { for (Map.Entry<K, V> entry : map.entrySet()) { if (value.equals(entry.getValue())) { return entry.getKey(); } } return null; } public static void printArray(int[] arr) { for (int i = 0 ; i < arr.length ; i++) { System.out.print(arr[i] + " "); } System.out.println(); } public static void swap(int[] arr) { for (int i = 0 ; i < arr.length ; i = i + 2) { int temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; } } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int highestPowerof2(int n) { int res = 0; for (int i = n; i >= 1; i--) { if ((i & (i - 1)) == 0) { res = i; break; } } return res; } public static int countElement(int[] arr, int k) { int cc = 0; for (int i = 0 ; i < arr.length ; i++ ) { if (arr[i] == k) { cc++; } } return cc; } public static long integerfrmbinary(String str) { long j = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == '1') { j = j + (long)Math.pow(2, str.length() - 1 - i); } } return (long) j; } static int maxInArray(int[] arr) { int max = arr[0]; for (int i = 0 ; i < arr.length ; i++) { if (arr[i] > max) { max = arr[i]; } } return max; } static void printN() { System.out.println("NO"); } static void printY() { System.out.println("YES"); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for (int v : a) { c0[(v & 0xff) + 1]++; c1[(v >>> 8 & 0xff) + 1]++; c2[(v >>> 16 & 0xff) + 1]++; c3[(v >>> 24 ^ 0x80) + 1]++; } for (int i = 0; i < 0xff; i++) { c0[i + 1] += c0[i]; c1[i + 1] += c1[i]; c2[i + 1] += c2[i]; c3[i + 1] += c3[i]; } int[] t = new int[n]; for (int v : a)t[c0[v & 0xff]++] = v; for (int v : t)a[c1[v >>> 8 & 0xff]++] = v; for (int v : a)t[c2[v >>> 16 & 0xff]++] = v; for (int v : t)a[c3[v >>> 24 ^ 0x80]++] = v; return a; } static int[] EvenOddArragement(int nums[]) { int i1 = 0, i2 = nums.length - 1; while (i1 < i2) { while (nums[i1] % 2 == 0 && i1 < i2) { i1++; } while (nums[i2] % 2 != 0 && i2 > i1) { i2--; } int temp = nums[i1]; nums[i1] = nums[i2]; nums[i2] = temp; } return nums; } static int gcd(int a, int b) { while (b != 0) { int t = a; a = b; b = t % b; } return a; } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int DigitSum(int n) { int r = 0, sum = 0; while (n >= 0) { r = n % 10; sum = sum + r; n = n / 10; } return sum; } static boolean checkPerfectSquare(int number) { double sqrt = Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static boolean isPowerOfTwo(int n) { if (n == 0) return false; return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static boolean isPrime2(int n) { if (n <= 1) { return false; } if (n == 2) { return true; } if (n % 2 == 0) { return false; } for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) { if (n % i == 0) { return false; } } return true; } static String minLexRotation(String str) { int n = str.length(); String arr[] = new String[n]; String concat = str + str; for (int i = 0; i < n; i++) { arr[i] = concat.substring(i, i + n); } Arrays.sort(arr); return arr[0]; } static String maxLexRotation(String str) { int n = str.length(); String arr[] = new String[n]; String concat = str + str; for (int i = 0; i < n; i++) { arr[i] = concat.substring(i, i + n); } Arrays.sort(arr); return arr[arr.length - 1]; } static class P implements Comparable<P> { int i, j; public P(int i, int j) { this.i = i; this.j = j; } public int compareTo(P o) { return Integer.compare(i, o.i); } } static class pair { int i, j; pair(int x, int y) { i = x; j = y; } } static int binary_search(int a[], int value) { int start = 0; int end = a.length - 1; int mid = start + (end - start) / 2; while (start <= end) { if (a[mid] == value) { return mid; } if (a[mid] > value) { end = mid - 1; } else { start = mid + 1; } mid = start + (end - start) / 2; } return -1; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
855f1697feed9a98cf8838383fa17066
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class G { static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } long[] getArr(int n) { long[] res = new long[n]; for(int i = 0; i < n; i++){ res[i] = Long.parseLong(next()); } return res; } } public static void main(String[] args) { FastScanner fs = new FastScanner(); int l = fs.nextInt(); while(l-- > 0) { int len = fs.nextInt(); // cho so chan int len1 = (len)/2; // cho so le int len2 = len - len1; Queue<Integer> list1 = new LinkedList<>(); Queue<Integer> list2 = new LinkedList<>(); if(len1 == len2){ if(len1 % 2== 0){ for(int i = 1; i <= len1; i++){ list1.add(i*2+1); list2.add(i*2); } } else{ // 4 1 2 12 3 8 list1.add(4); list1.add(2); list1.add(3); list2.add(1); list2.add(12); list2.add(8); int val = 100; while(list1.size() < len1){ list1.add(val * 2 + 1); list2.add(val*2); val += 1; } } } // len2 = len1 + 1 else{ if(len1 % 2 == 0){ for(int i = 1; i <= len1; i++){ list1.add(i*2+1); list2.add(i*2); } list1.add(0); } else{ for(int i = 1; i <= len1; i++){ list1.add(i*2+1); list2.add(i*2); } list1.add(1); } } while(!list1.isEmpty() || !list2.isEmpty()){ if(!list1.isEmpty()){ System.out.print(list1.poll()+" "); } if(!list2.isEmpty()){ System.out.print(list2.poll()+" "); } } System.out.println(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
d052521314d50d097f869d26ca28480a
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; public class Even_Odd1772G { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); getArr(n); } } static void getArr(int n) { int case1 = 0, case2 = 0; for (int i = 0; i < n - 2; ++i) { case1 ^= i; case2 ^= (i + 1); } long addLast = (1 << 31) -1; if (case1 != 0) { for (int i = 0; i < n - 2; ++i) { System.out.print(i + " "); } case1 ^= addLast; System.out.println(addLast + " " + case1); }else { for (int i = 0; i < n - 2; ++i) { System.out.print(i + 1 + " "); } case2 ^= addLast; System.out.println(addLast + " " + case2); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
b715faa28ba8813f833d6c8fe4b2cfe3
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class a { public static void main(String args[]) throws IOException { FastScanner in = new FastScanner(System.in); int t = in.nextInt(); for ( ; t > 0; t--) { int n = in.nextInt(); long[] vals = new long[n]; if (n == 3) { System.out.println(1 + " " + 2 + " " + 3); continue; } int amt = Math.max(0, n / 4 - 1) * 4; for (int i = 0; i < amt; i++) { vals[i] = i; } long max = (1 << 30) + (1 << 29) + (1 << 28) + (1 << 27); for (int i = amt; i < amt + 3; i++) { vals[i] = max + (i - amt + 1); } if (n % 4 == 0) { vals[n - 1] = max; } else if (n % 4 == 1) { vals[n - 2] = max & (1 << 27); vals[n - 1] = max & ((1 << 30) + (1 << 29) + (1 << 28)); } else if (n % 4 == 2) { vals[n - 3] = max & (1 << 30); vals[n - 2] = max & (1 << 27); vals[n - 1] = max & ((1 << 29) + (1 << 28)); } else if (n % 4 == 3) { vals[n - 4] = max & (1 << 28); vals[n - 3] = max & (1 << 30); vals[n - 2] = max & (1 << 27); vals[n - 1] = max & (1 << 29); } long val = 0; long even = 0; long odd = 0; for (int i = 0; i < n; i++) { val = val ^ vals[i]; if (i % 2 == 0) even ^= vals[i]; else odd ^= vals[i]; } for (int i = 0; i < n; i++) System.out.print(vals[i] + " "); System.out.println(); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream i) { br = new BufferedReader(new InputStreamReader(i)); st = new StringTokenizer(""); } public String next() throws IOException { if (st.hasMoreTokens()) return st.nextToken(); else st = new StringTokenizer(br.readLine()); return next(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
85e2d7edcca1c93d0b9c4c0d3b2377ba
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; public class Solution{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); long a[] = new long[n]; for(int i=0;i<n-3;i++){ a[i] = i; } a[n-3] = (long)Math.pow(2, 29); a[n-2] = (long)Math.pow(2, 30); long xor = 0; for(int i=0;i<n-1;i++){ xor ^= a[i]; } a[n-1] = xor; // xor = 0; for(long i : a){ System.out.print(i+" "); // xor = xor^i; } System.out.println(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
15bad345f7177d08c98d908a7524e54c
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; public class EvenOddXOR { public static void main(String[] args) { Scanner in = new Scanner(System.in); int inputs = in.nextInt(); for(int i = 0; i<inputs; i++){ int input = in.nextInt(); boolean even = true; if(input==3){ System.out.println("3 1 2"); continue; } if(input%2== 1){ input--; even = false; } boolean oddpairs = false; if((input/2)%2==1){ input-=2; oddpairs = true; } List<Integer> list = new ArrayList(); for(int x = 0; x<input/4;x++){ list.add(x*4+2); list.add(x*4+4); list.add(x*4+3); list.add(x*4+5); } if(oddpairs){ list.set(list.size()-1, list.get(list.size()-1)+65536); list.add(65536+ input+2); list.add(input+2); } if(!even){ list.add(0); } for(int j = 0; j<list.size();j++){ System.out.print(list.get(j)+ " "); } System.out.println(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
b9d674bac6385b72b3fa5436aa94edd9
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; public class Main { static Scanner in=new Scanner(System.in); public static void solve() { int n=in.nextInt(); int mod=(n-3)%4; if(mod==0) for(int i=1;i<=n;i++) { System.out.print(i+(i==n?"\n":" ")); } else { if(mod!=2){ for(int i=1;i<=n-3;i++)System.out.print(i+" "); if(mod==1) System.out.print((1<<29)+" "+(1<<30)+" "+1610612737+"\n"); else if(mod==3)System.out.print((1<<29)+" "+(1<<30)+" "+1610612736+"\n");} else{ for(int i=1;i<=n-4;i++)System.out.print(i+" "); System.out.print((1<<28)+" "+(1<<29)+" "+(1<<30)+" "+1879048193+"\n"); } } } public static void main(String[] args) { int t=in.nextInt(); while(t--!=0)solve(); } } /* 1 3 0 4 1 7 0 */
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
b7bfdf15a6d01edbae381f408779bf2f
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
// package c1722; // // Codeforces Round #817 (Div. 4) 2022-08-30 07:50 // G. Even-Odd XOR // https://codeforces.com/contest/1722/problem/G // time limit per test 1 second; memory limit per test 256 megabytes // public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*' // // Given an integer n, find any array a of n nonnegative integers less than 2^{31} such that the <a // href="https://en.wikipedia.org/wiki/Bitwise_operation#XOR">bitwise XOR</a> of the elements on odd // indices equals the bitwise XOR of the elements on even indices. // // Input // // The first line of the input contains an integer t (1 <= t <= 629)-- the number of test cases. // // Then t lines follow, each containing a single integer n (3 <= n <= 2*10^5)-- the length of the // array. // // It is guaranteed that the sum of n over all test cases does not exceed 2* 10^5. // // Output // // For each test case, output one line containing n distinct integers that satisfy the conditions. // // If there are multiple answers, you can output any of them. // // Example /* input: 7 8 3 4 5 6 7 9 output: 4 2 1 5 0 6 7 3 2 1 3 2 1 3 0 2 0 4 5 3 4 1 2 12 3 8 1 2 3 4 5 6 7 8 2 3 7 4 0 5 6 9 */ // Note // // In the first test case the XOR on odd indices is 4 ^ 1 ^ 0 ^ 7 = 2 and the XOR on even indices is // 2 ^ 5 ^ 6 ^ 3= 2. // import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.lang.invoke.MethodHandles; import java.util.HashSet; import java.util.Random; import java.util.Set; import java.util.StringTokenizer; public class C1722G { static final int MOD = 998244353; static final Random RAND = new Random(); static int[] solve(int n) { // n distinct 31 bits integers such that // XOR of m of them equals XOR of the other (n-m) where m = n / 2 int[] ans = new int[n]; Set<Integer> nums = new HashSet<>(); int maxv = (int) ((1L << 31) - 1); // Randomly select first n-2 values and ensure old != evn int old = 0; int evn = 0; for (int i = 0; i < n - 2; i++) { int v = 0; do { v = RAND.nextInt(maxv); } while(nums.contains(v)); ans[i] = v; if (i % 2 == 0) { evn ^= v; } else { old ^= v; } nums.add(v); } while (old == evn) { int i = RAND.nextInt(n-2); nums.remove(ans[i]); if (i % 2 == 0) { evn ^= ans[i]; } else { old ^= ans[i]; } int v = 0; do { v = RAND.nextInt(maxv); } while(nums.contains(v)); ans[i] = v; if (i % 2 == 0) { evn ^= v; } else { old ^= v; } nums.add(v); } myAssert(old != evn); // select the last two values int xor = old ^ evn; // x and y must disagree on set bits in xor and agree on other bits int disagree = xor & maxv; int agree = xor ^ maxv; while (true) { int z = RAND.nextInt(maxv) & agree; int w1 = RAND.nextInt(maxv) & disagree; int w2 = disagree ^ w1; if (nums.contains(z + w1) || nums.contains(z + w2)) { continue; } ans[n-2] = z + w1; ans[n-1] = z + w2; myAssert(verify(ans)); return ans; } } static boolean verify(int[] a) { int n = a.length; Set<Integer> nums = new HashSet<>(); int old = 0; int evn = 0; for (int i = 0; i < n; i++) { if (nums.contains(a[i])) { return false; } if (i % 2 == 0) { evn ^= a[i]; } else { old ^= a[i]; } nums.add(a[i]); } return old == evn; } static boolean test = false; static void doTest() { if (!test) { return; } long t0 = System.currentTimeMillis(); System.out.format("%d msec\n", System.currentTimeMillis() - t0); System.exit(0); } public static void main(String[] args) { doTest(); MyScanner in = new MyScanner(); int T = in.nextInt(); for (int t = 1; t <= T; t++) { int n = in.nextInt(); int[] ans = solve(n); output(ans); } } static void output(int[] a) { StringBuilder sb = new StringBuilder(); for (int v : a) { sb.append(v); sb.append(' '); if (sb.length() > 4000) { System.out.print(sb.toString()); sb.setLength(0); } } System.out.println(sb.toString()); } static void myAssert(boolean cond) { if (!cond) { throw new RuntimeException("Unexpected"); } } static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { try { final String USERDIR = System.getProperty("user.dir"); String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(".MyScanner", ""); cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname; final File fin = new File(USERDIR + "/io/c" + cname.substring(1,5) + "/" + cname + ".in"); br = new BufferedReader(new InputStreamReader(fin.exists() ? new FileInputStream(fin) : System.in)); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } public String next() { try { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } catch (Exception e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
97365e9eedfd9bbd70a947bd807eafcd
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
// package c1722; // // Codeforces Round #817 (Div. 4) 2022-08-30 07:50 // G. Even-Odd XOR // https://codeforces.com/contest/1722/problem/G // time limit per test 1 second; memory limit per test 256 megabytes // public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*' // // Given an integer n, find any array a of n nonnegative integers less than 2^{31} such that the <a // href="https://en.wikipedia.org/wiki/Bitwise_operation#XOR">bitwise XOR</a> of the elements on odd // indices equals the bitwise XOR of the elements on even indices. // // Input // // The first line of the input contains an integer t (1 <= t <= 629)-- the number of test cases. // // Then t lines follow, each containing a single integer n (3 <= n <= 2*10^5)-- the length of the // array. // // It is guaranteed that the sum of n over all test cases does not exceed 2* 10^5. // // Output // // For each test case, output one line containing n distinct integers that satisfy the conditions. // // If there are multiple answers, you can output any of them. // // Example /* input: 7 8 3 4 5 6 7 9 output: 4 2 1 5 0 6 7 3 2 1 3 2 1 3 0 2 0 4 5 3 4 1 2 12 3 8 1 2 3 4 5 6 7 8 2 3 7 4 0 5 6 9 */ // Note // // In the first test case the XOR on odd indices is 4 ^ 1 ^ 0 ^ 7 = 2 and the XOR on even indices is // 2 ^ 5 ^ 6 ^ 3= 2. // import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.lang.invoke.MethodHandles; import java.util.HashSet; import java.util.Random; import java.util.Set; import java.util.StringTokenizer; public class C1722G { static final int MOD = 998244353; static final Random RAND = new Random(); static int[] solve(int n) { // n distinct 31 bits integers such that // XOR of m of them equals XOR of the other (n-m) where m = n / 2 int m = n / 2; // choose(31,6)=736281 exceeds 200000 int[] ans = new int[n]; Set<Integer> nums = new HashSet<>(); int maxv = (int) ((1L << 31) - 1); int old = 0; int evn = 0; for (int i = 0; i < n - 2; i++) { int v = 0; do { v = RAND.nextInt(maxv); } while(nums.contains(v)); ans[i] = v; if (i % 2 == 0) { evn ^= v; } else { old ^= v; } nums.add(v); } while (old == evn) { int i = RAND.nextInt(n-2); nums.remove(ans[i]); if (i % 2 == 0) { evn ^= ans[i]; } else { old ^= ans[i]; } int v = 0; do { v = RAND.nextInt(maxv); } while(nums.contains(v)); ans[i] = v; if (i % 2 == 0) { evn ^= v; } else { old ^= v; } nums.add(v); } myAssert(old != evn); int xor = old ^ evn; // x and y must disagree on set bits in xor and agree on other bits int disagree = xor & maxv; int agree = xor ^ maxv; while (true) { int z = RAND.nextInt(maxv) & agree; int w1 = RAND.nextInt(maxv) & disagree; int w2 = disagree ^ w1; if (nums.contains(z + w1) || nums.contains(z + w2)) { continue; } ans[n-2] = z + w1; ans[n-1] = z + w2; myAssert(verify(ans)); return ans; } } static boolean verify(int[] a) { int n = a.length; Set<Integer> nums = new HashSet<>(); int old = 0; int evn = 0; for (int i = 0; i < n; i++) { if (nums.contains(a[i])) { return false; } if (i % 2 == 0) { evn ^= a[i]; } else { old ^= a[i]; } nums.add(a[i]); } return old == evn; } static boolean test = false; static void doTest() { if (!test) { return; } long t0 = System.currentTimeMillis(); System.out.format("%d msec\n", System.currentTimeMillis() - t0); System.exit(0); } public static void main(String[] args) { doTest(); MyScanner in = new MyScanner(); int T = in.nextInt(); for (int t = 1; t <= T; t++) { int n = in.nextInt(); int[] ans = solve(n); output(ans); } } static void output(int[] a) { StringBuilder sb = new StringBuilder(); for (int v : a) { sb.append(v); sb.append(' '); if (sb.length() > 4000) { System.out.print(sb.toString()); sb.setLength(0); } } System.out.println(sb.toString()); } static void myAssert(boolean cond) { if (!cond) { throw new RuntimeException("Unexpected"); } } static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { try { final String USERDIR = System.getProperty("user.dir"); String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(".MyScanner", ""); cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname; final File fin = new File(USERDIR + "/io/c" + cname.substring(1,5) + "/" + cname + ".in"); br = new BufferedReader(new InputStreamReader(fin.exists() ? new FileInputStream(fin) : System.in)); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } public String next() { try { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } catch (Exception e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
6131ad202856d0408394bcc11f36736f
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
// package c1722; // // Codeforces Round #817 (Div. 4) 2022-08-30 07:50 // G. Even-Odd XOR // https://codeforces.com/contest/1722/problem/G // time limit per test 1 second; memory limit per test 256 megabytes // public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*' // // Given an integer n, find any array a of n nonnegative integers less than 2^{31} such that the <a // href="https://en.wikipedia.org/wiki/Bitwise_operation#XOR">bitwise XOR</a> of the elements on odd // indices equals the bitwise XOR of the elements on even indices. // // Input // // The first line of the input contains an integer t (1 <= t <= 629)-- the number of test cases. // // Then t lines follow, each containing a single integer n (3 <= n <= 2*10^5)-- the length of the // array. // // It is guaranteed that the sum of n over all test cases does not exceed 2* 10^5. // // Output // // For each test case, output one line containing n distinct integers that satisfy the conditions. // // If there are multiple answers, you can output any of them. // // Example /* input: 7 8 3 4 5 6 7 9 output: 4 2 1 5 0 6 7 3 2 1 3 2 1 3 0 2 0 4 5 3 4 1 2 12 3 8 1 2 3 4 5 6 7 8 2 3 7 4 0 5 6 9 */ // Note // // In the first test case the XOR on odd indices is 4 ^ 1 ^ 0 ^ 7 = 2 and the XOR on even indices is // 2 ^ 5 ^ 6 ^ 3= 2. // import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.lang.invoke.MethodHandles; import java.util.HashSet; import java.util.Random; import java.util.Set; import java.util.StringTokenizer; public class C1722G { static final int MOD = 998244353; static final Random RAND = new Random(); static int[] solve(int n) { // n distinct 31 bits integers such that // XOR of m of them equals XOR of the other (n-m) where m = n / 2 int m = n / 2; // choose(31,6)=736281 exceeds 200000 int[] ans = new int[n]; Set<Integer> nums = new HashSet<>(); int maxv = (int) ((1L << 31) - 1); int old = 0; int evn = 0; for (int i = 0; i < n - 2; i++) { int v = 0; do { v = RAND.nextInt(maxv); } while(nums.contains(v)); ans[i] = v; if (i % 2 == 0) { evn ^= v; } else { old ^= v; } nums.add(v); } while (true) { while (old == evn) { int i = RAND.nextInt(n-2); nums.remove(ans[i]); if (i % 2 == 0) { evn ^= ans[i]; } else { old ^= ans[i]; } int v = 0; do { v = RAND.nextInt(maxv); } while(nums.contains(v)); ans[i] = v; if (i % 2 == 0) { evn ^= v; } else { old ^= v; } nums.add(v); } myAssert(old != evn); int xor = old ^ evn; // x and y must disagree on set bits in xor and agree on other bits int disagree = xor & maxv; int agree = xor ^ maxv; while (true) { int z = RAND.nextInt(maxv) & agree; int w1 = RAND.nextInt(maxv) & disagree; int w2 = disagree ^ w1; if (nums.contains(z + w1) || nums.contains(z + w2)) { continue; } ans[n-2] = z + w1; ans[n-1] = z + w2; myAssert(verify(ans)); return ans; } } } static boolean verify(int[] a) { int n = a.length; Set<Integer> nums = new HashSet<>(); int old = 0; int evn = 0; for (int i = 0; i < n; i++) { if (nums.contains(a[i])) { return false; } if (i % 2 == 0) { evn ^= a[i]; } else { old ^= a[i]; } nums.add(a[i]); } return old == evn; } static boolean test = false; static void doTest() { if (!test) { return; } long t0 = System.currentTimeMillis(); System.out.format("%d msec\n", System.currentTimeMillis() - t0); System.exit(0); } public static void main(String[] args) { doTest(); MyScanner in = new MyScanner(); int T = in.nextInt(); for (int t = 1; t <= T; t++) { int n = in.nextInt(); int[] ans = solve(n); output(ans); } } static void output(int[] a) { StringBuilder sb = new StringBuilder(); for (int v : a) { sb.append(v); sb.append(' '); if (sb.length() > 4000) { System.out.print(sb.toString()); sb.setLength(0); } } System.out.println(sb.toString()); } static void myAssert(boolean cond) { if (!cond) { throw new RuntimeException("Unexpected"); } } static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { try { final String USERDIR = System.getProperty("user.dir"); String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(".MyScanner", ""); cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname; final File fin = new File(USERDIR + "/io/c" + cname.substring(1,5) + "/" + cname + ".in"); br = new BufferedReader(new InputStreamReader(fin.exists() ? new FileInputStream(fin) : System.in)); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } public String next() { try { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } catch (Exception e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
896477a0ff72a0c76bf3f5dae8c9a13c
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Test { static long mod = 1000000007; static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); int t = sc.nextInt(); while( t-- > 0) { int n = sc.nextInt(); int arr[] = new int[n]; int temp = 1 << 21; if( n%2 == 0) { if( (n/2)%2 == 0) { for( int i = 0 ; i < n; i+=2) { arr[i] = i+1; arr[i+1] = arr[i]^temp; } } else { for( int i = 0; i< n; i+=2) { if( i == n-2) { arr[i] = (i+1)^temp; } else { arr[i] = i+1; } } for( int i =1 ; i< n ;i+=2) { if( i == n-1) { arr[i] = i; } else if( i == n-3) { arr[i] = i^temp^(2*temp); } else { arr[i] = i^(2*temp); } } } } else { if( (n-3)%4 != 0) { for( int i =0 ; i< n ;i+=2) { if( i == n-1) { arr[i] = temp; } else { arr[i] = i+1; arr[i+1] = arr[i]; } } for( int i =1 ;i < n; i+=2) { if( i == n-2) { arr[i]^=temp; arr[i]^=(2*temp); } else { arr[i]^=(2*temp); } } } else { for( int i =0 ; i< n ;i+=2) { if( i == n-1) { arr[i] = temp; } else { arr[i] = i+1; arr[i+1] = arr[i]; } } for( int i =1 ; i< n; i+=2) { arr[i]^=temp; } } } int fst = 0; int scnd =0; for( int i = 0 ;i < n; i++) { if( i%2 == 0) fst^=arr[i]; else scnd^=arr[i]; out.print(arr[i] + " "); } out.println(); // out.println(fst + " " +scnd); } out.flush(); } static int[] nge( int arr[] , int n ) { int ans[] = new int[n]; Stack<Integer> s = new Stack<>(); for( int i = n-1 ; i>=0 ; i--) { while( !s.isEmpty() && arr[s.peek()] < arr[i]) { s.pop(); } if( !s.isEmpty()) ans[i] = s.peek(); else ans[i] = -1; s.add(i); } return ans; } /* * think of binary search * look at test cases * do significant case work */ static class DSU{ int n; int[] leaders,size; public DSU(int n){ this.n=n; leaders=new int[n+1]; size=new int[n+1]; for(int i=1;i<=n;i++){ leaders[i]=i; size[i]=1; } } public int find(int a){ if(leaders[a]==a) return a; return leaders[a]=find (leaders[a]); } public void merge(int a,int b){ a = find(a); b = find(b); if (a == b) return; if (size[a] < size[b]) swap(a, b); leaders[b] = a; size[a] += size[b]; } public void swap(int a,int b){ int temp=a; a=b; b=temp; } } static long power(long x, long y, long p) { long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res%p; } public static boolean ifpowof2(long n ) { return ((n&(n-1)) == 0); } static boolean isprime(long x ) { if( x== 2) { return true; } if( x%2 == 0) { return false; } for( long i = 3 ;i*i <= x ;i+=2) { if( x%i == 0) { return false; } } return true; } static boolean[] sieveOfEratosthenes(long n) { boolean prime[] = new boolean[(int)n + 1]; for (int i = 0; i <= n; i++) { prime[i] = true; } for (long p = 2; p * p <= n; p++) { if (prime[(int)p] == true) { for (long i = p * p; i <= n; i += p) prime[(int)i] = false; } } return prime; } public List<Integer> goodIndices(int[] nums, int k) { int n = nums.length; int fst[] = nextLargerElement(nums, n); int scnd[] = nextlargerElement(nums, n); List<Integer> ans = new ArrayList<>(); for( int i = 0 ;i < n; i++) { if( fst[i] == -1 || scnd[i] == -1) { continue; } if( fst[i]-i >= k && i - scnd[i] >= k) { ans.add(i); } } return ans; } public static int[] nextLargerElement(int[] arr, int n) { Stack<Integer> stack = new Stack<>(); int rtrn[] = new int[n]; rtrn[n-1] = -1; stack.push( n-1); for( int i = n-2 ;i >= 0 ; i--){ int temp = arr[i]; int lol = -1; while( !stack.isEmpty() && arr[stack.peek()] <= temp){ if(arr[stack.peek()] == temp ) { lol = stack.peek(); } stack.pop(); } if( stack.isEmpty()){ if( lol != -1) { rtrn[i] = lol; } else { rtrn[i] = -1; } } else{ rtrn[i] = stack.peek(); } stack.push( i); } return rtrn; } public static int[] nextlargerElement(int[] arr, int n) { Stack<Integer> stack = new Stack<>(); int rtrn[] = new int[n]; rtrn[0] = -1; stack.add( 0); for( int i = 1 ;i < n ; i++){ int temp = arr[i]; int lol = -1; while( !stack.isEmpty() && arr[stack.peek()] <= temp){ if(arr[stack.peek()] == temp ) { lol = stack.peek(); } stack.pop(); } if( stack.isEmpty()){ if( lol != -1) { rtrn[i] = lol; } else { rtrn[i] = -1; } } else{ rtrn[i] = stack.peek(); } stack.add( i); } return rtrn; } static void mysort(int[] arr) { for(int i=0;i<arr.length;i++) { int rand = (int) (Math.random() * arr.length); int loc = arr[rand]; arr[rand] = arr[i]; arr[i] = loc; } Arrays.sort(arr); } static void mySort(long[] arr) { for(int i=0;i<arr.length;i++) { int rand = (int) (Math.random() * arr.length); long loc = arr[rand]; arr[rand] = arr[i]; arr[i] = loc; } Arrays.sort(arr); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long rightmostsetbit(long n) { return n&-n; } static long leftmostsetbit(long n) { long k = (long)(Math.log(n) / Math.log(2)); return k; } static HashMap<Long,Long> primefactor( long n){ HashMap<Long ,Long> hm = new HashMap<>(); long temp = 0; while( n%2 == 0) { temp++; n/=2; } if( temp!= 0) { hm.put( 2L, temp); } long c = (long)Math.sqrt(n); for( long i = 3 ; i <= c ; i+=2) { temp = 0; while( n% i == 0) { temp++; n/=i; } if( temp!= 0) { hm.put( i, temp); } } if( n!= 1) { hm.put( n , 1L); } return hm; } static TreeSet<Long> allfactors(long abs) { HashMap<Long,Integer> hm = new HashMap<>(); TreeSet<Long> rtrn = new TreeSet<>(); rtrn.add(1L); for( long i = 2 ;i*i <= abs; i++) { if( abs% i == 0) { hm.put( i , 0); hm.put(abs/i, 0); } } for( long x : hm.keySet()) { rtrn.add(x); } if( abs != 0) { rtrn.add(abs); } return rtrn; } public static int[][] prefixsum( int n , int m , int arr[][] ){ int prefixsum[][] = new int[n+1][m+1]; for( int i = 1 ;i <= n ;i++) { for( int j = 1 ; j<= m ; j++) { int toadd = 0; if( arr[i-1][j-1] == 1) { toadd = 1; } prefixsum[i][j] = toadd + prefixsum[i][j-1] + prefixsum[i-1][j] - prefixsum[i-1][j-1]; } } return prefixsum; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
c7db00325fcb167037a9baf1c209e997
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class G_Even_Odd_XOR { static long mod = Long.MAX_VALUE; public static void main(String[] args) { OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); FastReader f = new FastReader(); int t = f.nextInt(); while(t-- > 0){ solve(f, out); } out.close(); } public static void solve(FastReader f, PrintWriter out) { int n = f.nextInt(); if(n == 3) { out.println("2 1 3"); return; } ArrayList<Integer> arrli = new ArrayList<>(); int xor = 0; for(int i = 0; i < n-3; i++) { arrli.add(i); xor ^= i; } if((xor^(n-3)) == 0) { arrli.add(n-2); xor ^= (n-2); } else { arrli.add(n-3); xor ^= (n-3); } arrli.add((1<<29)); xor ^= (1 << 29); arrli.add(xor); for(int i: arrli) { out.print(i + " "); } out.println(); } // Sort an array public static void sort(int arr[]) { ArrayList<Integer> al = new ArrayList<>(); for(int i: arr) { al.add(i); } Collections.sort(al); for(int i = 0; i < arr.length; i++) { arr[i] = al.get(i); } } // Find all divisors of n public static void allDivisors(int n) { for(int i = 1; i*i <= n; i++) { if(n%i == 0) { System.out.println(i + " "); if(i != n/i) { System.out.println(n/i + " "); } } } } // Check if n is prime or not public static boolean isPrime(int n) { if(n < 1) return false; if(n == 2 || n == 3) return true; if(n % 2 == 0 || n % 3 == 0) return false; for(int i = 5; i*i <= n; i += 6) { if(n % i == 0 || n % (i+2) == 0) { return false; } } return true; } // Find gcd of a and b public static long gcd(long a, long b) { long dividend = a > b ? a : b; long divisor = a < b ? a : b; while(divisor > 0) { long reminder = dividend % divisor; dividend = divisor; divisor = reminder; } return dividend; } // Find lcm of a and b public static long lcm(long a, long b) { long lcm = gcd(a, b); long hcf = (a * b) / lcm; return hcf; } // Find factorial in O(n) time public static long fact(int n) { long res = 1; for(int i = 2; i <= n; i++) { res = res * i; } return res; } // Find power in O(logb) time public static long power(long a, long b) { long res = 1; while(b > 0) { if((b&1) == 1) { res = (res * a)%mod; } a = (a * a)%mod; b >>= 1; } return res; } // Find nCr public static long nCr(int n, int r) { if(r < 0 || r > n) { return 0; } long ans = fact(n) / (fact(r) * fact(n-r)); return ans; } // Find nPr public static long nPr(int n, int r) { if(r < 0 || r > n) { return 0; } long ans = fact(n) / fact(r); return ans; } // sort all characters of a string public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } // User defined class for fast I/O static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } boolean hasNext() { if (st != null && st.hasMoreTokens()) { return true; } String tmp; try { br.mark(1000); tmp = br.readLine(); if (tmp == null) { return false; } br.reset(); } catch (IOException e) { return false; } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } boolean nextBoolean() { return Boolean.parseBoolean(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextArray(int n) { int[] a = new int[n]; for(int i=0; i<n; i++) { a[i] = nextInt(); } return a; } } } /** Dec Char Dec Char Dec Char Dec Char --------- --------- --------- ---------- 0 NUL (null) 32 SPACE 64 @ 96 ` 1 SOH (start of heading) 33 ! 65 A 97 a 2 STX (start of text) 34 " 66 B 98 b 3 ETX (end of text) 35 # 67 C 99 c 4 EOT (end of transmission) 36 $ 68 D 100 d 5 ENQ (enquiry) 37 % 69 E 101 e 6 ACK (acknowledge) 38 & 70 F 102 f 7 BEL (bell) 39 ' 71 G 103 g 8 BS (backspace) 40 ( 72 H 104 h 9 TAB (horizontal tab) 41 ) 73 I 105 i 10 LF (NL line feed, new line) 42 * 74 J 106 j 11 VT (vertical tab) 43 + 75 K 107 k 12 FF (NP form feed, new page) 44 , 76 L 108 l 13 CR (carriage return) 45 - 77 M 109 m 14 SO (shift out) 46 . 78 N 110 n 15 SI (shift in) 47 / 79 O 111 o 16 DLE (data link escape) 48 0 80 P 112 p 17 DC1 (device control 1) 49 1 81 Q 113 q 18 DC2 (device control 2) 50 2 82 R 114 r 19 DC3 (device control 3) 51 3 83 S 115 s 20 DC4 (device control 4) 52 4 84 T 116 t 21 NAK (negative acknowledge) 53 5 85 U 117 u 22 SYN (synchronous idle) 54 6 86 V 118 v 23 ETB (end of trans. block) 55 7 87 W 119 w 24 CAN (cancel) 56 8 88 X 120 x 25 EM (end of medium) 57 9 89 Y 121 y 26 SUB (substitute) 58 : 90 Z 122 z 27 ESC (escape) 59 ; 91 [ 123 { 28 FS (file separator) 60 < 92 \ 124 | 29 GS (group separator) 61 = 93 ] 125 } 30 RS (record separator) 62 > 94 ^ 126 ~ 31 US (unit separator) 63 ? 95 _ 127 DEL */ // (a/b)%mod == (a * moduloInverse(b)) % mod; // moduloInverse(b) = power(b, mod-2);
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
a347945a2ea0411ce5bd809a090c5e8c
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main{ static class pair{ int x ;int y ; pair(int x ,int y ) { this.x=x; this.y =y; } } static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void prlong(Object object) throws IOException { bw.append("" + object); } public void prlongln(Object object) throws IOException { prlong(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } //dsu static int[] parent,rank; public static void dsu(int n){ parent = new int[n]; rank = new int[n]; for(int i =0;i<n;i++){ parent[i]=i; rank[i]=1; } } public static int find(int i){ if(i==parent[i] ) return i; return parent[i]=find(parent[i]); } static int f(int arr[],int i ) { if(i==arr[i]) return i ; return arr[i]=f(arr,arr[i]); } public static void merge(int i, int j){ i=find(i); j=find(j); if(rank[i]>=rank[j]){ rank[i]+=rank[j]; parent[j]=i; } else { rank[j]+=rank[i]; parent[i]=j; } } public static int help(boolean[] v){ HashSet<Integer> s = new HashSet<>(); for(int e=1;e<v.length;e++){ int i=find(e); if(v[i]) s.add(i); } // System.out.print(Arrays.toString(parent)); return s.size(); } public static void main(String[] args) { try { FastReader in = new FastReader(); FastWriter out = new FastWriter(); long testCases =in.nextLong(); fl: while (testCases-- > 0) { int n =in.nextInt(); long xor =0; for(int i =0;i<n-3;i++) { System.out.print(i+" "); xor=xor^i; } xor =xor^(int)Math.pow(2,28); xor =xor^(int)Math.pow(2,29); System.out.print((int)Math.pow(2,28)+" "+(int)Math.pow(2,29)+" "+xor); System.out.println(); } out.close(); } catch (Exception e) { return; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
b231e6bbc5ca1a5e8225e051269d4cc3
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; public class Main{ static class pair{ int x ;int y ; pair(int x ,int y ) { this.x=x; this.y =y; } } static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void prlong(Object object) throws IOException { bw.append("" + object); } public void prlongln(Object object) throws IOException { prlong(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } //dsu static int[] parent,rank; public static void dsu(int n){ parent = new int[n]; rank = new int[n]; for(int i =0;i<n;i++){ parent[i]=i; rank[i]=1; } } public static int find(int i){ if(i==parent[i] ) return i; return parent[i]=find(parent[i]); } static int f(int arr[],int i ) { if(i==arr[i]) return i ; return arr[i]=f(arr,arr[i]); } public static void merge(int i, int j){ i=find(i); j=find(j); if(rank[i]>=rank[j]){ rank[i]+=rank[j]; parent[j]=i; } else { rank[j]+=rank[i]; parent[i]=j; } } public static int help(boolean[] v){ HashSet<Integer> s = new HashSet<>(); for(int e=1;e<v.length;e++){ int i=find(e); if(v[i]) s.add(i); } // System.out.print(Arrays.toString(parent)); return s.size(); } public static void main(String[] args) { try { FastReader in = new FastReader(); FastWriter out = new FastWriter(); long testCases =in.nextLong(); fl: while (testCases-- > 0) { int n =in.nextInt(); long xor =0; for(int i =1;i<=n-3;i++) { System.out.print(i+" "); xor=xor^i; } xor =xor^(int)Math.pow(2,29); xor =xor^(int)Math.pow(2,30); System.out.print((int)Math.pow(2,29)+" "+(int)Math.pow(2,30)+" "+xor); System.out.println(); } out.close(); } catch (Exception e) { return; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
4f43f250df9812204fab1c62cc6ed733
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Stack; public class aaaaaa { static Scanner sc; public static void solve() { int n = sc.nextInt(); int [] arr = new int[n]; if((n&1) == 1){ for(int i=1, j=1; i<n; i+=2, j++){ arr[i] = j; } for(int i=2, j=1; i<n; i+=2, j++){ arr[i] = j; } } else{ for(int i=0, j=1; i<n; i+=2, j++){ arr[i] = j; } for(int i=1, j=1; i<n; i+=2, j++){ arr[i] = j; } } if((((n+1)/2)&1) == 1){ for(int i=0; i+2<n; i+=2){ arr[i] |= (1<<30); } for(int i=2; i<n; i+=2){ arr[i] |= (1<<29); } } else{ for(int i=0; i<n; i+=2){ arr[i] |= (1<<30); } } for(int num : arr){ System.out.print(num + " "); } System.out.println(); } public static void main(String[] args) { sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0){ solve(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
166b3a6e092158e9d30d7143706cbc25
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; //4 public class Main { public static void main(String arg[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int T = Integer.parseInt(br.readLine()); while(T --> 0) { int n = Integer.parseInt(br.readLine()); int case1 = 0; int case2 = 0; for(int i = 1; i < n-2; i++) { sb.append(i+" "); if(i%2 == 0) { case1 ^= i; } else case2 ^= i; } if(n % 2 == 0) { int case3 = (1 << 30); int case4 = (1 << 29); sb.append((case3+case1)+" "); sb.append((case4+case2)+" "); sb.append((case3+(1<<29))+"\n"); } else { int case3 = (1 << 30); int case4 = (1 << 29); sb.append((case3+case2)+" "); sb.append((case4+case1)+" "); sb.append((case3+(1<<29))+"\n"); } } System.out.println(sb); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
93ed55a41a75729abc662f4f6fab5006
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.math.BigDecimal; import java.util.*; public class Main{ static int[][] v = {{2, 1, 3, 0}, {2,0,4,5,3}, {4,1,2,12,3,8}, {2,1,3}}; static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); static StreamTokenizer st = new StreamTokenizer(bf); public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = I(); while(t-->0) { int n = I(); solve(n); } pw.flush(); } static void solve(int n) { int k = n%4,ans = 100; for (int i = 0 ; i< v[k].length ; i++) pw.print(v[k][i]+" "); int q = 0; while(q < n-v[k].length) { q++; pw.print(ans+" "); ans++; } pw.println(); } static int I() throws IOException { st.nextToken(); return (int)st.nval; } static long L() throws IOException { st.nextToken(); return (long)st.nval; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
1a6fc2b5934cedc9280bb03dd8720135
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
// 17-05 // import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class D { public static void main(String[] args) { Scanner sc = new Scanner(); int t = sc.nextInt(); PrintWriter out = new PrintWriter(System.out); while (t-- > 0) { int n = sc.nextInt(); if (n % 4 == 0) { for (int i = 2; i < n + 2; i++) { out.print(i + " "); } } else if (n % 4 == 1) { out.print(0 + " "); n -= 1; for (int i = 2; i < n + 2; i++) { out.print(i + " "); } } else if (n % 4 == 2) { n -= 6; out.print(4 + " " + 1 + " " + 2 + " " + 12 + " " + 3 + " " + 8 + " "); for (int i = 14; i < n + 14; i++) { out.print(i + " "); } } else { n -= 3; out.print(2 + " " + 1 + " " + 3 + " "); for (int i = 6; i < n + 6; i++) { out.print(i + " "); } } out.println(); } out.flush(); out.close(); } static class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } String str = ""; String nextLine() { try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } static void sort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n), temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } static final int M = 1_000_000_007; static final int inf = Integer.MAX_VALUE; static final int ninf = inf + 1; }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
3bb68d0da4378a49d5c1c3390a9d1347
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.Scanner; public class pb7 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0){ int n = sc.nextInt(); int start = 2; if (n % 4 == 1){ System.out.print(0 + " "); n -= 1; } else if (n% 4 == 3){ System.out.print(2 + " " + 3 + " " + 1 + " "); start = 4; n -=3; } else if (n % 4 == 2){ System.out.print(2 + " " + 3 + " " + 1 + " " + 4 + " " + 8 + " "+ 12 + " "); n -= 6; start = 16; } for (int i = 0 ; i< n ; i++){ System.out.print(start+ " "); start++; } System.out.println(); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
de17c5e0551a9f29af99839a64709c55
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; public class EvenOddXor { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int N = Integer.parseInt(br.readLine()); while (N-- > 0) { int n = Integer.parseInt(br.readLine()); int a = 0; for (int i = 0; i < n-3; i++) { a ^= i; pw.print(i + " "); } if (a == n-1) { a ^= (n-2); pw.print((n-2) + " "); } else { a ^= (n-1); pw.print((n-1) + " "); } a += 1 << 30; pw.print((1<<30) + " "); pw.println(a); } pw.close(); br.close(); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
3ed1de3f15e46de44428dbf25691deae
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.*; import java.util.*; public class G { static PrintWriter out; static Kioken sc; static boolean checkOnlineJudge = System.getProperty("ONLINE_JUDGE") == null; public static void main(String[] args) throws FileNotFoundException { if (checkOnlineJudge) { out = new PrintWriter("E:/CF_V2/output.txt"); sc = new Kioken(new File("E:/CF_V2/input.txt")); } else { out = new PrintWriter((System.out)); sc = new Kioken(); } int tt = 1; tt = sc.nextInt(); while (tt-- > 0) { solve(); } out.flush(); out.close(); } public static void solve() { int n = sc.nextInt(); if(n == 3){ out.println(1 + " " + 3 + " " + 2); return; } long[] ans = new long[n]; if(n%2 == 0){ int val = 1; for(int i = 0; i < n; i+=2){ ans[i] = val; val++; } val = 1; for(int i = 1; i < n; i+=2){ ans[i] = (1 << 21) + val; val++; } if(n%4 != 0){ ans[n - 1] -= (1 << 21); for(int i = n - 1; i >= 2; i -= 2){ ans[i] += (1 << 20); } } }else{ int val = 1; for(int i = 0; i < n; i+=2){ ans[i] = val; val++; } val = 1; for(int i = 1; i < n; i+=2){ ans[i] = (1 << 21) + val; val++; } ans[n - 1] = 0; if((n-1)%4 != 0){ ans[n - 2] -= (1 << 21); for(int i = n - 2; i >= 2; i -= 2){ ans[i] += (1 << 20); } } } long evenXor = 0L, oddXor = 0L; for(int i = 0; i < n; i+=2){ evenXor = evenXor^ans[i]; } for(int i = 1; i < n; i+=2){ oddXor = oddXor^ans[i]; } if(evenXor != oddXor){ out.println(" NO ---> "); } for(long i : ans){ out.print(i + " "); } out.println(); } public static long gcd(long a, long b) { while (b != 0) { long rem = a % b; a = b; b = rem; } return a; } static long MOD = 1000000007; static void reverseSort(int[] arr){List<Integer> list = new ArrayList<>();for (int i=0; i<arr.length; i++){list.add(arr[i]);}Collections.sort(list, Collections.reverseOrder());for (int i = 0; i < arr.length; i++){arr[i] = list.get(i);}} static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a){ ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class Kioken { // FileInputStream br = new FileInputStream("input.txt"); BufferedReader br; StringTokenizer st; Kioken(File filename) { try { FileReader fr = new FileReader(filename); br = new BufferedReader(fr); st = new StringTokenizer(""); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } Kioken() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } public boolean hasNext() { String next = null; try { next = br.readLine(); } catch (Exception e) { } if (next == null || next.length() == 0) { return false; } st = new StringTokenizer(next); return true; } public int[] readArrayInt(int n){ int[] arr = new int[n]; for(int i = 0; i < n; i++){ arr[i] = nextInt(); } return arr; } public long[] readArrayLong(int n){ long[] arr = new long[n]; for(int i = 0; i < n; i++){ arr[i] = nextLong(); } return arr; } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
a8015595b3f75d3f9c54c5899bd100e2
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; public class G { public static void main(String [] args){ Scanner sc= new Scanner(System.in); int t=sc.nextInt(); for(;t>0;t--){ int n=sc.nextInt(); int res[] = new int[n]; int odd=0; int even=0; /* if(n%4==2){ for (int i = 0; i < n; i++) { if(i%2==0) res[i]=i; else res[i] = i+2; if(i%2==0 && i<n-2) even=even^i; } } else*/ if(n%2==0){ for (int i = 0; i < n; i++) { res[i] = i; if(i%2==0 ) even=even^i; else if (i%2==1)odd=odd^i; } } else { for (int i = 0; i < n; i++) { res[i] = i + 1; } } // System.out.println(n+" "+(n&-n)); if(n%4==1) res[0]=0; else if(n%4==2){ res[n-1]=res[n-1]|(res[n-1]<<1); res[0]=n; res[1]=res[n-1]-3; } odd=0; even=0; for(int i=0; i<n; i++){ System.out.print(res[i]+" "); // if(i%2==0) even=even^res[i]; // else odd= odd^res[i]; } System.out.println(); // System.out.println(even+" "+odd); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
c569380f1ff281b6e1986c42f0a7c6e5
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class New { public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int testCases = Integer.parseInt(br.readLine()); while(testCases-->0){ int n=Integer.parseInt(br.readLine()); int arr[]=new int[n]; if(n%2==0) { for(int i=0,j=1;i<n;i+=2,j++) arr[i]=j; for(int i=1,j=1;i<n;i+=2,j++) arr[i]=j; }else { for(int i=2,j=1;i<n;i+=2,j++) arr[i]=j; for(int i=1,j=1;i<n;i+=2,j++) arr[i]=j; } if(((n+1)/2)%2==0) { for(int i=0;i<n;i+=2) { arr[i]|=(1<<30); } }else { for(int i=0;i+2<n;i+=2) { arr[i]|=(1<<30); } for(int i=2;i<n;i+=2) { arr[i]|=(1<<29); } } for(int i:arr) out.print(i+" "); out.println(); } out.close(); } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
748d72b7d3322dd40741b6aa89463fcc
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { static InputStream is; static PrintWriter out; static String INPUT = ""; static final int ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE; static final long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE; static final long mod = (long) 1e9 + 7; static void solve() { int caseNo = 1; for (int T = sc.nextInt(); T > 1; T--, caseNo++) { solveIt(caseNo); } solveIt(caseNo); } // Solution static void solveIt(int testCaseNo) { int n = sc.nextInt(); int x = 0; for (int i = 1; i <= n - 3; i++) { out.print(i + " "); x ^= i; } out.print((1 << 29) + " "); out.print((1 << 30) + " "); x ^= (1 << 29); x ^= (1 << 30); out.print(x + " "); out.println(); } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); solve(); out.flush(); long G = System.currentTimeMillis(); sc.tr(G - S + "ms"); } static class sc { private static boolean endOfFile() { if (bufferLength == -1) return true; int lptr = ptrbuf; while (lptr < bufferLength) { if (!isThisTheSpaceCharacter(inputBufffferBigBoi[lptr++])) return false; } try { is.mark(1000); while (true) { int b = is.read(); if (b == -1) { is.reset(); return true; } else if (!isThisTheSpaceCharacter(b)) { is.reset(); return false; } } } catch (IOException e) { return true; } } private static byte[] inputBufffferBigBoi = new byte[1024]; static int bufferLength = 0, ptrbuf = 0; private static int justReadTheByte() { if (bufferLength == -1) throw new InputMismatchException(); if (ptrbuf >= bufferLength) { ptrbuf = 0; try { bufferLength = is.read(inputBufffferBigBoi); } catch (IOException e) { throw new InputMismatchException(); } if (bufferLength <= 0) return -1; } return inputBufffferBigBoi[ptrbuf++]; } private static boolean isThisTheSpaceCharacter(int c) { return !(c >= 33 && c <= 126); } private static int skipItBishhhhhhh() { int b; while ((b = justReadTheByte()) != -1 && isThisTheSpaceCharacter(b)); return b; } private static double nextDouble() { return Double.parseDouble(next()); } private static char nextChar() { return (char) skipItBishhhhhhh(); } private static String next() { int b = skipItBishhhhhhh(); StringBuilder sb = new StringBuilder(); while (!(isThisTheSpaceCharacter(b))) { sb.appendCodePoint(b); b = justReadTheByte(); } return sb.toString(); } private static char[] readCharArray(int n) { char[] buf = new char[n]; int b = skipItBishhhhhhh(), p = 0; while (p < n && !(isThisTheSpaceCharacter(b))) { buf[p++] = (char) b; b = justReadTheByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private static char[][] readCharMatrix(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = readCharArray(m); return map; } private static int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } private static long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } private static int nextInt() { int num = 0, b; boolean minus = false; while ((b = justReadTheByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if (b == '-') { minus = true; b = justReadTheByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = justReadTheByte(); } } private static long nextLong() { long num = 0; int b; boolean minus = false; while ((b = justReadTheByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if (b == '-') { minus = true; b = justReadTheByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = justReadTheByte(); } } private static void tr(Object... o) { if (INPUT.length() != 0) System.out.println(Arrays.deepToString(o)); } } } // And I wish you could sing along, But this song is a joke, and the melody I // wrote, wrong
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
3581a3bf496aa881d809fe5e92f60592
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
//Some of the methods are copied from GeeksforGeeks Website import java.util.*; import java.lang.*; import java.io.*; @SuppressWarnings("unchecked") public class Main { //static Scanner sc=new Scanner(System.in); //static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); static long mod = (long)(1e9)+ 7; static int max_num=(int)1e5+5; static List<Integer> gr[]; public static void main (String[] args) throws java.lang.Exception { try{ /* out.println("Case #"+tt+": "+ans ); gr=new ArrayList[n]; for(int i=0;i<n;i++) gr[i]=new ArrayList<>(); while(l<=r) { int m=l+(r-l)/2; if(val(m)) { ans=m; l=m+1; } else r=m-1; } Collections.sort(al,Collections.reverseOrder()); StringBuilder sb=new StringBuilder(""); sb.append(cur); sb=sb.reverse(); String rev=sb.toString(); map.put(a[i],map.getOrDefault(a[i],0)+1); map.putIfAbsent(x,new ArrayList<>()); long n=sc.nextLong(); String s=sc.next(); char a[]=s.toCharArray(); */ int t = sc.nextInt(); for(int tt=1;tt<=t;tt++) { int n=sc.nextInt(); int xor=0; int a[]=new int[n]; for(int i=0;i<n-2;i++) { a[i]=i; xor^=a[i]; } int p=(int)Math.pow(2l,31l); a[n-2]=p; if(xor==0) { for(int i=0;i<n-2;i++) { a[i]++; xor^=a[i]; } } xor^=a[n-2]; a[n-1]=xor; print(a); } out.flush(); out.close(); } catch(Exception e) {} } /* ...SOLUTION ENDS HERE...........SOLUTION ENDS HERE... */ static void flag(boolean flag) { out.println(flag ? "YES" : "NO"); out.flush(); } /* Map<Long,Long> map=new HashMap<>(); for(int i=0;i<n;i++) { if(!map.containsKey(a[i])) map.put(a[i],1); else map.replace(a[i],map.get(a[i])+1); } Set<Map.Entry<Long,Long>> hmap=map.entrySet(); for(Map.Entry<Long,Long> data : hmap) { } Iterator<Integer> itr = set.iterator(); while(itr.hasNext()) { int val=itr.next(); } */ // static class Pair // { // int x,y; // Pair(int x,int y) // { // this.x=x; // this.y=y; // } // } // Arrays.sort(p, new Comparator<Pair>() // { // @Override // public int compare(Pair o1,Pair o2) // { // if(o1.x>o2.x) return 1; // else if(o1.x==o2.x) // { // if(o1.y>o2.y) return 1; // else return -1; // } // else return -1; // }}); static void print(int a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print(long a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print_int(ArrayList<Integer> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void print_long(ArrayList<Long> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void pn(int x) { out.println(x); out.flush(); } static void pn(long x) { out.println(x); out.flush(); } static void pn(String x) { out.println(x); out.flush(); } static int LowerBound(int a[], int x) { int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static void DFS(ArrayList<Integer> graph[],boolean[] visited, int u) { visited[u]=true; int v=0; for(int i=0;i<graph[u].size();i++) { v=graph[u].get(i); if(!visited[v]) DFS(graph,visited,v); } } static boolean[] prime(int num) { boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false; } } } if(num >= 0) { bool[0] = false; bool[1] = false; } return bool; } static long nCr(long a,long b,long mod) { return (((fact[(int)a] * modInverse(fact[(int)b],mod))%mod * modInverse(fact[(int)(a - b)],mod))%mod + mod)%mod; } static long fact[]=new long[max_num]; static void fact_fill() { fact[0]=1l; for(int i=1;i<max_num;i++) { fact[i]=(fact[i-1]*(long)i); if(fact[i]>=mod) fact[i]%=mod; } } static long modInverse(long a, long m) { return power(a, m - 2, m); } static long power(long x, long y, long m) { if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (long)((p * (long)p) % m); if (y % 2 == 0) return p; else return (long)((x * (long)p) % m); } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static long sum_array(long a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void reverse_array(int a[]) { int n=a.length; int i,t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static void reverse_array(long a[]) { int n=a.length; int i; long t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; } // Thank You !
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
0091808b035dbb6e2871247f9f9e1fe3
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.io.*; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.math.BigInteger; public class Main{ static class Node { long sum, pre; Node(long a, long b) { this.sum = a; this.pre = b; } } static class SegmentTree { int l , r; // range responsible for SegmentTree left , right; long val; SegmentTree(int l,int r,long a[]) { this.l = l; this.r = r; // list= new ArrayList<>(); if(l == r) { val = a[l]; return ; } int mid = l + (r-l)/2; this.left = new SegmentTree(l ,mid , a); this.right = new SegmentTree(mid + 1 , r,a); this.val = Math.max(this.left.val , this.right.val); } public long query(int left ,int right) { if(this.l > right || this.r < left) { return 0l; } if(this.l >= left && this.r <= right) { return this.val; } return this.left.query(left , right ) + this.right.query(left , right ); } // public void pointUpdate(int index , long val) { // if(this.l > index || this.r < index) return; // if(this.l == this.r && this.l == index) { // this.val = val; // return ; // } // this.left.pointUpdate(index ,val); // this.right.pointUpdate(index , val); // this.val = join(this.left.val , this.right.val); // } // public void rangeUpdate(int left , int right,long val) { // if(this.l > right || this.r < left) return ; // if(this.l >= left && this.r <= right) { // this.val += val; // } // if(this.l == this.r) return; // this.left.rangeUpdate(left , right , val); // this.right.rangeUpdate(left , right , val); // } // public long valueAtK(int k) { // if(this.l > k || this.r < k) return 0; // if(this.l == this.r && this.l == k) { // return this.val; // } // return join(this.left.valueAtK(k) , this.right.valueAtK(k)); // } public int join(int a ,int b) { return a + b; } } static class Hash { long hash[] ,mod = (long)1e9 + 7 , powT[] , prime , inverse[]; Hash(char []s) { prime = 131; int n = s.length; powT = new long[n]; hash = new long[n]; inverse = new long[n]; powT[0] = 1; inverse[n-1] = pow(pow(prime , n-1 ,mod), mod-2 , mod); for(int i = 1;i < n; i++ ) { powT[i] = (powT[i-1]*prime)%mod; } for(int i = n-2; i>= 0;i-=1) { inverse[i] = (inverse[i+1]*prime)%mod; } hash[0] = (s[0] - 'a' + 1); for(int i = 1; i < n;i++ ) { hash[i] = hash[i-1] + ((s[i]-'a' + 1)*powT[i])%mod; hash[i] %= mod; } } public long hashValue(int l , int r) { if(l == 0) return hash[r]%mod; long ans = hash[r] - hash[l-1] +mod; ans %= mod; // System.out.println(inverse[l] + " " + pow(powT[l], mod- 2 , mod)); ans *= inverse[l]; ans %= mod; return ans; } } static class ConvexHull { Stack<Integer>stack; Stack<Integer>stack1; int n; Point arr[]; ConvexHull(Point arr[]) { n = arr.length; this.arr = arr; Arrays.sort(arr , (a , b)-> { if(a.x == b.x) return (int)(b.y-a.y); return (int)(a.x-b.x); }); Point min = arr[0]; stack = new Stack<>(); stack1 = new Stack<>(); stack.push(0); stack1.push(0); Point ob = new Point(2,2); for(int i =1;i < n;i++) { if(stack.size() < 2) stack.push(i); else { while(stack.size() >= 2) { int a = stack.pop() , b = stack.pop() ,c = i; int dir = ob.cross(arr[b] , arr[a] , arr[c]); if(dir < 0) { stack.push(b); stack.push(a); stack.push(c); break; } stack.push(b); } if(stack.size() < 2) { stack.push(i); } } } for(int i =1;i < n;i++) { if(stack1.size() < 2) stack1.push(i); else { while(stack1.size() >= 2) { int a = stack1.pop() , b = stack1.pop() ,c = i; int dir = ob.cross(arr[b] , arr[a] , arr[c]); if(dir > 0) { stack1.push(b); stack1.push(a); stack1.push(c); break; } stack1.push(b); } if(stack1.size() < 2) { stack1.push(i); } } } } public List<Point> getPoints() { boolean vis[] = new boolean[n]; List<Point> list = new ArrayList<>(); // for(int x : stack) { // list.add(arr[x]); // vis[x] = true; // } for(int x : stack1) { // if(vis[x]) continue; list.add(arr[x]); } return list; } } public static class Suffix implements Comparable<Suffix> { int index; int rank; int next; public Suffix(int ind, int r, int nr) { index = ind; rank = r; next = nr; } public int compareTo(Suffix s) { if (rank != s.rank) return Integer.compare(rank, s.rank); return Integer.compare(next, s.next); } } static class Point { long x , y; Point(long x , long y) { this.x = x; this.y = y; } // public String toString() { // return this.x + " " + this.y; // } public Point sub(Point a,Point b) { return new Point(a.x - b.x , a.y-b.y); } public int cross(Point a ,Point b , Point c) { Point g = sub(b,a) , l = sub(c, b); long ans = g.y*l.x - g.x*l.y; if(ans == 0) return 0; if(ans < 0) return -1; return 1; } } static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in, System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(new FileWriter(problemName + ".out")); r = new BufferedReader(new FileReader(problemName + ".in")); } // returns null if no more input public String next() { try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(r.readLine()); return st.nextToken(); } catch (Exception e) { } return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } static Kattio sc = new Kattio(); static long mod = 998244353l; // static Kattio out = new Kattio(); //Heapify function to maintain heap property. public static void swap(int i,int j,int arr[]) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } public static long max(long ...a) { return maxArray(a); } public static void swap(int i,int j,long arr[]) { long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } public static void swap(int i,int j,char arr[]) { char temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static String endl = "\n" , gap = " "; static int size[]; static int parent[]; static HashMap<Integer , Long> value; // static HashMap<String , Boolean > dp; // static HashMap<Integer , List<int[]>> graph; static boolean vis[]; static int answer; static HashSet<String> guess; static long primePow[]; // static long dp[]; static int N; static int dis[]; static int height[]; static long p[]; // static long fac[]; // static long inv[]; static HashMap<Integer ,List<Integer>> graph; public static long rd() { return (long)((Math.random()*10) + 1); } public static void main(String[] args)throws IOException { long t = ri(); // List<Integer> list = new ArrayList<>(); // int MAX = (int)4e4; // for(int i =1;i<=MAX;i++) { // if(isPalindrome(i + "")) list.add(i); // } // // System.out.println(list); // long dp[] = new long[MAX +1]; // dp[0] = 1; // long mod = (long)(1e9+7); // for(int x : list) { // for(int i =1;i<=MAX;i++) { // if(i >= x) { // dp[i] += dp[i-x]; // dp[i] %= mod; // } // } // } // int MAK = (int)1e6 + 10; // boolean seive[] = new boolean[MAK]; // Arrays.fill(seive , true); // seive[1] = false; // seive[0] = false; // for (int i = 1; i < MAK; i++) { // if(seive[i]) { // for (int j = i+i; j < MAK; j+=i) { // seive[j] = false; // } // } // } // TreeSet<Long>primeSet = new TreeSet<>(); // for(long i = 2;i <= (long)1e6;i++) { // if(seive[(int)i])primeSet.add(i); // } // List<Integer> list = new ArrayList<>(); // for (int i = 1; i < seive.length; i++) { // if(seive[i]) list.add(i); // } int test_case = 1; while(t-->0) { // sc.print("Case #"+(test_case++)+": "); solve(); } sc.close(); } static int endTime[]; static int time; public static int dis(int a[] , int b[]) { return (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]); } // static Long dp[][][]; static long fac[], inv[]; public static long ncr(int a , int b) { if(a == b) return 1l; return (((fac[a]*inv[b])%mod)*inv[a-b])%mod; } static Long dp[][]; static HashMap<String , Long> dmap; static long dirpair[][]; static HashSet<String> not; // long subsum[]; public static void solve() throws IOException { int n= ri(); long a[] = new long[n]; int odd = 0 , even = 0; for(int i =1 ;i <= n-2;i++) { a[i-1] = i*1l; if((i-1)%2 == 0)odd ^= i; else even ^= i; } long p = 1l<<30l; if(odd == even) { a[n-3] = n-3 + 7; if((n-3)%2 == 0) { even ^= (n-2); even ^= (n-3 + 7); } else { even ^= (n-2); even ^= (n-3 + 7); } } if((n-2)%2 == 0) { a[n-2] = p; a[n-1] = p^odd^even; } else { a[n-2] = p; a[n-1] = odd^p^even; } // long A = 0 , B =0; // for(int i =0;i < n;i++) { // if(i%2 == 0) A^= a[i]; // else B^= a[i]; // } // System.out.println(A==B);sb for(long x : a) { sc.print(x + " "); } sc.println(); } public static long solve(long r , long c, int m) { if(m == 0) return 1l; String key = r + " " + c + " " + m; if(dmap.containsKey(key)) return dmap.get(key); long ans = 0 , mod = 998244353L; for(int i =0;i < 3;i++) { long nr = r + dirpair[i][0] , nc = c + dirpair[i][1]; if(not.contains(nr + " " + nc)) continue; ans += solve(nr , nc , m-1); ans %= mod; } dmap.put(key , ans); return ans; } public static long lcm(long x , long y) { return x/gcd(x , y)*y; } public static void print(PriorityQueue<long[]> que ) { for(long a[] : que) { System.out.print(a[1] + " "); } System.out.println(); } public static String slope(Point a , Point b) { if((a.x-b.x) == 0) return "inf"; long n = a.y- b.y; if(n == 0) return "0"; long m = a.x-b.x; boolean neg = (n*m < 0?true:false); n = Math.abs(n); m = Math.abs(m); long g = gcd(Math.abs(n),Math.abs(m)); n /= g; m /= g; String ans = n+"/"+m; if(neg) ans = "-" + ans; return ans; } public static int lis(int A[], int size) { int[] tailTable = new int[size]; int len; tailTable[0] = A[0]; len = 1; for (int i = 1; i < size; i++) { if (A[i] < tailTable[0]) tailTable[0] = A[i]; else if (A[i] > tailTable[len - 1]) tailTable[len++] = A[i]; else tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]; } return len; } public static int CeilIndex(int A[], int l, int r, int key) { while (r - l > 1) { int m = l + (r - l) / 2; if (A[m] >= key) r = m; else l = m; } return r; } public static int lcs(char a[] , char b[]) { int n = a.length , m = b.length; int dp[][] = new int[n + 1][m + 1]; for(int i =1;i <= n;i++) { for(int j =1;j <= m;j++) { if(a[i-1] == b[j-1]) dp[i][j] = 1 + dp[i-1][j-1]; else dp[i][j] = Math.max(dp[i-1][j] , dp[i][j-1]); } } return dp[n][m]; } public static int find(int node) { if(node == parent[node]) return node; return parent[node] = find(parent[node]); } public static void merge(int a ,int b ) { a = find(a); b = find(b); if(a == b) return; if(size[a] >= size[b]) { parent[b] = a; size[a] += size[b]; // primePow[a] += primePow[b]; // primePow[b] = 0; } else { parent[a] = b; size[b] += size[a]; // primePow[b] += primePow[a]; // primePow[a] = 0; } } public static void processPowerOfP(long arr[]) { int n = arr.length; arr[0] = 1; long mod = (long)1e9 + 7; for(int i =1;i<n;i++) { arr[i] = arr[i-1]*51; arr[i] %= mod; } } public static long hashValue(char s[]) { int n = s.length; long powerOfP[] = new long[n]; processPowerOfP(powerOfP); long ans =0; long mod = (long)1e9 + 7; for(int i =0;i<n;i++) { ans += (s[i]-'a'+1)*powerOfP[i]; ans %= mod; } return ans; } public static void dfs(int r,int c,char arr[][]) { int n = arr.length , m = arr[0].length; arr[r][c] = '#'; for(int i =0;i<4;i++) { int nr = r + colx[i] , nc = c + coly[i]; if(nr < 0 || nc < 0 || nc >= m || nr>=n) continue; if(arr[nr][nc] == '#') continue; dfs(nr,nc,arr); } } public static double getSlope(int a , int b,int x,int y) { if(a-x == 0) return Double.MAX_VALUE; if(b-y == 0) return 0.0; return ((double)b-(double)y)/((double)a-(double)x); } public static boolean collinearr(long a[] , long b[] , long c[]) { return (b[1]-a[1])*(b[0]-c[0]) == (b[0]-a[0])*(b[1]-c[1]); } public static boolean isSquare(long sum) { long root = (int)Math.sqrt(sum); return root*root == sum; } public static int[] suffixArray(String s) { int n = s.length(); Suffix[] su = new Suffix[n]; for (int i = 0; i < n; i++) { su[i] = new Suffix(i, s.charAt(i) - '$', 0); } for (int i = 0; i < n; i++) su[i].next = (i + 1 < n ? su[i + 1].rank : -1); Arrays.sort(su); int[] ind = new int[n]; for (int length = 4; length < 2 * n; length <<= 1) { int rank = 0, prev = su[0].rank; su[0].rank = rank; ind[su[0].index] = 0; for (int i = 1; i < n; i++) { if (su[i].rank == prev && su[i].next == su[i - 1].next) { prev = su[i].rank; su[i].rank = rank; } else { prev = su[i].rank; su[i].rank = ++rank; } ind[su[i].index] = i; } for (int i = 0; i < n; i++) { int nextP = su[i].index + length / 2; su[i].next = nextP < n ? su[ind[nextP]].rank : -1; } Arrays.sort(su); } int[] suf = new int[n]; for (int i = 0; i < n; i++) suf[i] = su[i].index; return suf; } public static boolean isPalindrome(String s) { int i =0 , j = s.length() -1; while(i <= j && s.charAt(i) == s.charAt(j)) { i++; j--; } return i>j; } // digit dp hint; public static long callfun(String num , int N, int last ,int secondLast ,int bound ,long dp[][][][]) { if(N == 1) { if(last == -1 || secondLast == -1) return 0; long answer = 0; int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9; for(int i = 0;i<=max;i++) { if(last > secondLast && last > i) { answer++; } if(last < secondLast && last < i) { answer++; } } return answer; } if(secondLast == -1 || last == -1 ){ long answer = 0l; int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9; for(int i =0;i<=max;i++) { int nl , nsl , newbound = bound==0?0:i==max?1:0; if(last == - 1&& secondLast == -1 && i == 0) { nl = -1 ; nsl = -1; } else { nl = i;nsl = last; } long temp = callfun(num , N-1 , nl , nsl ,newbound, dp); answer += temp; if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++; } return answer; } if(dp[N][last][secondLast][bound] != -1) return dp[N][last][secondLast][bound]; long answer = 0l; int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9; for(int i =0;i<=max;i++) { int nl , nsl , newbound = bound==0?0:i==max?1:0; if(last == - 1&& secondLast == -1 && i == 0) { nl = -1 ; nsl = -1; } else { nl = i;nsl = last; } long temp = callfun(num , N-1 , nl , nsl ,newbound,dp); answer += temp; if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++; } return dp[N][last][secondLast][bound] = answer; } public static Long callfun(int index ,int pair,int arr[],Long dp[][]) { long mod = 998244353l; if(index >= arr.length) return 1l; if(dp[index][pair] != null) return dp[index][pair]; Long sum = 0l , ans = 0l; if(arr[index]%2 == pair) { return dp[index][pair] = callfun(index + 1,pair^1 , arr,dp)%mod + callfun(index + 1 ,pair , arr , dp)%mod; } else { return dp[index][pair] = callfun(index + 1,pair , arr,dp)%mod; } // for(int i =index;i<arr.length;i++) { // sum += arr[i]; // if(sum%2 == pair) { // ans = ans + callfun(i + 1,pair^1,arr , dp)%mod; // ans%=mod; // } // } // return dp[index][pair] = ans; } public static boolean callfun(int index , int n,int neg , int pos , String s) { if(neg < 0 || pos < 0) return false; if(index >= n) return true; if(s.charAt(0) == 'P') { if(neg <= 0) return false; return callfun(index + 1,n , neg-1 , pos , s.charAt(1) + "N"); } else { if(pos <= 0) return false; return callfun(index + 1 , n , neg , pos-1 , s.charAt(1) + "P"); } } public static void getPerm(int n , char arr[] , String s ,List<String>list) { if(n == 0) { list.add(s); return; } for(char ch : arr) { getPerm(n-1 , arr , s+ ch,list); } } public static int getLen(int i ,int j , char s[]) { while(i >= 0 && j < s.length && s[i] == s[j]) { i--; j++; } i++; j--; if(i>j) return 0; return j-i + 1; } public static int getMaxCount(String x) { char s[] = x.toCharArray(); int max = 0; int n = s.length; for(int i =0;i<n;i++) { max = Math.max(max,Math.max(getLen(i , i,s) , getLen(i ,i+1,s))); } return max; } public static double getDis(int arr[][] , int x, int y) { double ans = 0.0; for(int a[] : arr) { int x1 = a[0] , y1 = a[1]; ans += Math.sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1)); } return ans; } public static boolean valid(String x ) { if(x.length() == 0) return true; if(x.length() == 1) return false; char s[] = x.toCharArray(); if(x.length() == 2) { if(s[0] == s[1]) { return false; } return true; } int r = 0 , b = 0; for(char ch : x.toCharArray()) { if(ch == 'R') r++; else b++; } return (r >0 && b >0); } public static void primeDivisor(HashMap<Long , Long >cnt , long num) { for(long i = 2;i*i<=num;i++) { while(num%i == 0) { cnt.put(i ,(cnt.getOrDefault(i,0l) + 1)); num /= i; } } if(num > 2) { cnt.put(num ,(cnt.getOrDefault(num,0l) + 1)); } } public static boolean isSubsequene(char a[], char b[] ) { int i =0 , j = 0; while(i < a.length && j <b.length) { if(a[i] == b[j]) { j++; } i++; } return j >= b.length; } public static long fib(int n ,long M) { if (n == 0) { return 0; } else if (n == 1) { return 1; } else { long[][] mat = {{1, 1}, {1, 0}}; mat = pow(mat, n-1 , M); return mat[0][0]; } } public static long[][] pow(long[][] mat, int n ,long M) { if (n == 1) return mat; else if (n % 2 == 0) return pow(mul(mat, mat , M), n/2 , M); else return mul(pow(mul(mat, mat,M), n/2,M), mat , M); } static long[][] mul(long[][] p, long[][] q,long M) { long a = (p[0][0]*q[0][0] + p[0][1]*q[1][0])%M; long b = (p[0][0]*q[0][1] + p[0][1]*q[1][1])%M; long c = (p[1][0]*q[0][0] + p[1][1]*q[1][0])%M; long d = (p[1][0]*q[0][1] + p[1][1]*q[1][1])%M; return new long[][] {{a, b}, {c, d}}; } public static long[] kdane(long arr[]) { int n = arr.length; long dp[] = new long[n]; dp[0] = arr[0]; long ans = dp[0]; for(int i = 1;i<n;i++) { dp[i] = Math.max(dp[i-1] + arr[i] , arr[i]); ans = Math.max(ans , dp[i]); } return dp; } public static void update(int low , int high , int l , int r, int val , int treeIndex ,int tree[]) { if(low > r || high < l || high < low) return; if(l <= low && high <= r) { System.out.println("At " +low + " and " + high + " ans ttreeIndex " + treeIndex); tree[treeIndex] += val; return; } int mid = low + (high - low)/2; update(low , mid , l , r , val , treeIndex*2 + 1, tree); update(mid + 1 , high , l , r , val , treeIndex*2 + 2 , tree); } // static int colx[] = {1 ,1, -1,-1 , 2,2,-2,-2}; // static int coly[] = {-2 ,2, 2,-2,1,-1,1,-1}; static int colx[] = {1 ,-1, 0,0 , 1,1,-1,-1}; static int coly[] = {0 ,0, 1,-1,1,-1,1,-1}; public static void reverse(char arr[]) { int i =0 , j = arr.length-1; while(i < j) { swap(i , j , arr); i++; j--; } } public static void reverse(long arr[]) { int i =0 , j = arr.length-1; while(i < j) { swap(i , j , arr); i++; j--; } } public static void reverse(int arr[]) { int i =0 , j = arr.length-1; while(i < j) { swap(i , j , arr); i++; j--; } } public static long inverse(long x , long mod) { return pow(x , mod -2 , mod); } public static int maxArray(int arr[]) { int ans = arr[0] , n = arr.length; for(int i =1;i<n;i++) { ans = Math.max(ans , arr[i]); } return ans; } public static long maxArray(long arr[]) { long ans = arr[0]; int n = arr.length; for(int i =1;i<n;i++) { ans = Math.max(ans , arr[i]); } return ans; } public static int minArray(int arr[]) { int ans = arr[0] , n = arr.length; for(int i =0;i<n;i++ ) { ans = Math.min(ans ,arr[i]); } return ans; } public static long minArray(long arr[]) { long ans = arr[0]; int n = arr.length; for(int i =0;i<n;i++ ) { ans = Math.min(ans ,arr[i]); } return ans; } public static int sumArray(int arr[]) { int ans = 0; for(int x : arr) { ans += x; } return ans; } public static long sumArray(long arr[]) { long ans = 0; for(long x : arr) { ans += x; } return ans; } public static long rl() { return sc.nextLong(); } public static char[] rac() { return sc.next().toCharArray(); } public static String rs() { return sc.next(); } public static char rc() { return sc.next().charAt(0); } public static int [] rai(int n) { int ans[] = new int[n]; for(int i =0;i<n;i++) { ans[i] = sc.nextInt(); } return ans; } public static long [] ral(int n) { long ans[] = new long[n]; for(int i =0;i<n;i++) { ans[i] = sc.nextLong(); } return ans; } public static int ri() { return sc.nextInt(); } public static int getValue(int num ) { int ans = 0; while(num > 0) { ans++; num = num&(num-1); } return ans; } public static boolean isValid(int x ,int y , int n,char arr[][],boolean visited[][][][]) { return x>=0 && x<n && y>=0 && y <n && !(arr[x][y] == '#'); } // public static Pair join(Pair a , Pair b) { // Pair res = new Pair(Math.min(a.min , b.min) , Math.max(a.max , b.max) , a.count + b.count); // return res; // } // segment tree query over range // public static int query(int node,int l , int r,int a,int b ,Pair tree[] ) { // if(tree[node].max < a || tree[node].min > b) return 0; // if(l > r) return 0; // if(tree[node].min >= a && tree[node].max <= b) { // return tree[node].count; // } // int mid = l + (r-l)/2; // int ans = query(node*2 ,l , mid ,a , b , tree) + query(node*2 +1,mid + 1, r , a , b, tree); // return ans; // } // // segment tree update over range // public static void update(int node, int i , int j ,int l , int r,long value, long arr[] ) { // if(l >= i && j >= r) { // arr[node] += value; // return; // } // if(j < l|| r < i) return; // int mid = l + (r-l)/2; // update(node*2 ,i ,j ,l,mid,value, arr); // update(node*2 +1,i ,j ,mid + 1,r, value , arr); // } public static long pow(long a , long b , long mod) { if(b == 1) return a; if(b == 0) return 1; long ans = pow(a , b/2 , mod)%mod; if(b%2 == 0) { return (ans*ans)%mod; } else { return ((ans*ans)%mod*a)%mod; } } public static long pow(long a , long b ) { if(b == 1) return a; if(b == 0) return 1; long ans = pow(a , b/2); if(b%2 == 0) { return (ans*ans); } else { return ((ans*ans)*a); } } public static boolean isVowel(char ch) { if(ch == 'a' || ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') return true; if((ch == 'A' || ch == 'E'||ch == 'I' || ch == 'O' || ch == 'U')) return true; return false; } // public static int getFactor(int num) { // if(num==1) return 1; // int ans = 2; // int k = num/2; // for(int i = 2;i<=k;i++) { // if(num%i==0) ans++; // } // return Math.abs(ans); // } public static int[] readarr()throws IOException { int n = sc.nextInt(); int arr[] = new int[n]; for(int i =0;i<n;i++) { arr[i] = sc.nextInt(); } return arr; } public static boolean isPowerOfTwo (long x) { return x!=0 && ((x&(x-1)) == 0); } public static boolean isPrime(long num) { if(num==1) return false; if(num<=3) return true; if(num%2==0||num%3==0) return false; for(long i =5;i*i<=num;i+=6) { if(num%i==0 || num%(i+2) == 0) return false; } return true; } public static boolean isPrime(int num) { // System.out.println("At pr " + num); if(num==1) return false; if(num<=3) return true; if(num%2==0||num%3==0) return false; for(int i =5;i*i<=num;i+=6) { if(num%i==0 || num%(i+2) == 0) return false; } return true; } // public static boolean isPrime(long num) { // if(num==1) return false; // if(num<=3) return true; // if(num%2==0||num%3==0) return false; // for(int i =5;i*i<=num;i+=6) { // if(num%i==0) return false; // } // return true; // } public static void allMultiple() { // int MAX = 0 , n = nums.length; // for(int x : nums) MAX = Math.max(MAX ,x); // int cnt[] = new int[MAX + 1]; // int ans[] = new int[MAX + 1]; // for (int i = 0; i < n; ++i) cnt[nums[i]]++; // for (int i = 1; i <= MAX; ++i) { // for (int j = i; j <= MAX; j += i) ans[i] += cnt[j]; // } } public static long gcd(long a , long b) { if (b == 0) return a; return gcd(b, a % b); } public static int gcd(int a , int b) { if (b == 0) return a; return gcd(b, a % b); } public static int get_gcd(int a , int b) { if (b == 0) return a; return gcd(b, a % b); } public static long get_gcd(long a , long b) { if (b == 0) return a; return gcd(b, a % b); } // public static long fac(long num) { // long ans = 1; // int mod = (int)1e9+7; // for(long i = 2;i<=num;i++) { // ans = (ans*i)%mod; // } // return ans; // } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
213c1dcd3df30f3f04ff5ccb372fbf9b
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.util.*; import java.text.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter writer = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int arr[] = new int[n]; int p = 1; while(p<n)p*=2; int s1 = 0; int s2 = (n+1)/2; for(int i = 0; i < n; i++) { if(i%2==0) { arr[i] = s1++; }else { arr[i] = s2++; } } if(n%2==0) { if((n/2)%2==1) { arr[n-1]--; arr[n-1]+=p; arr[0] = p; } }else { int arr1[] = new int[32]; int arr2[] = new int[32]; for(int i = 0; i < n; i++) { if(i%2==0) { for(int j = 0; j < 32; j++) { if(((arr[i]>>j)&1)==1)arr1[j]++; } }else { for(int j = 0; j < 32; j++) { if(((arr[i]>>j)&1)==1)arr2[j]++; } } } // writer.println(Arrays.toString(arr1)); // writer.println(Arrays.toString(arr2)); int ans = arr[n-2]; for(int j = 0; j < 32; j++) { if(arr1[j]%2 != arr2[j]%2) { if( ((ans>>j)&1)==1) { ans-=(1<<j); }else { ans+=(1<<j); } } } arr[n-2]=p+ans; if(arr[0]+p != arr[n-2])arr[0]+=p; else arr[2]+=p; } for(int i : arr)writer.print(i + " "); // int xor1 = 0; // int xor2 = 0; // for(int i = 0 ; i < n; i++) { // if(i%2==0) { // xor1^=arr[i]; // }else { // xor2^=arr[i]; // } // } writer.println(); // if(xor1 != xor2)writer.println(n); } writer.flush(); writer.close(); } public static long lcm(long x,long y) { return x/gcd(x, y)*y; } private static long power (long a, long n, long p) { long res = 1; while(n!=0) { if(n%2==1) { res=(res*a)%p; n--; }else { a= (a*a)%p; n/=2; } } return res; } private static boolean isPrime(int c) { for (int i = 2; i*i <= c; i++) { if(c%i==0)return false; } return true; } private static int find(int a , int arr[]) { if(arr[a] != a) return arr[(int)a] = find(arr[(int)a], arr); return arr[(int)a]; } private static void union(int a, int b, int arr[]) { int aa = find(a,arr); int bb = find(b, arr); arr[aa] = bb; } private static long gcd(long a, long b) { if(a==0)return b; return gcd(b%a, a); } public static int[] readIntArray(int size, FastReader s) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = s.nextInt(); } return array; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } class SegmentTree{ int size; long arr[]; SegmentTree(int n){ size = 1; while(size<n)size*=2; arr = new long[size*2]; } public void build(int input[]) { build(input, 0,0, size); } public void set(int i, int v) { set(i,v,0,0,size); } // sum from l + r-1 public long sum(int l, int r) { return sum(l,r,0,0,size); } private void build(int input[], int x, int lx, int rx) { if(rx-lx==1) { if(lx < input.length ) arr[x] = 1; return; } int mid = (lx+rx)/2; build(input, 2*x+1, lx, mid); build(input,2*x+2,mid,rx); arr[x] = arr[2*x+1] + arr[2*x+2]; } private void set(int i, int v, int x, int lx, int rx) { if(rx-lx==1) { arr[x]++; return; } int mid = (lx+rx)/2; if(i < mid) set(i, v, 2*x+1, lx, mid); else set(i,v,2*x+2,mid,rx); arr[x] = arr[2*x+1] + arr[2*x+2]; } private long sum(int l, int r, int x, int lx, int rx) { if(lx>=r || rx <= l)return 0; if(lx>=l && rx <= r)return arr[x]; int mid = (lx+rx)/2; long s1 = sum(l,r,2*x+1,lx,mid); long s2 = sum(l,r,2*x+2,mid,rx); return s2+s1; } // int first_above(int v, int l, int x, int lx, int rx) { // if(arr[x].a<v)return -1; // if(rx<=l)return -1; // if(rx-lx==1)return lx; // int m = (lx+rx)/2; // int res = first_above(v,l,2*x+1,lx,m); // if(res==-1)res = first_above(v,l,2*x+2,m,rx); // return res; // // } } class Pair implements Comparable<Pair>{ long a; long b; long c; Pair(long a, long b, long c){ this.a = a; this.b = b; this.c = c; } Pair(long a, long b){ this.a = a; this.b = b; this.c = 0; } @Override public boolean equals(Object obj) { if(this == obj) return true; if(obj == null || obj.getClass()!= this.getClass()) return false; Pair pair = (Pair) obj; return (pair.a == this.a && pair.b == this.b && pair.c == this.c); } @Override public int hashCode() { // return Objects.hash(a,b); return new Long(a).hashCode() * 31 + new Long(b).hashCode(); } @Override public int compareTo(Pair o) { if(o.a != this.a) return Long.compare(this.a, o.a); else return Long.compare(this.b, o.b); } @Override public String toString() { return this.a + " " + this.b; } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output
PASSED
5c248f9a5e7fa175731c40a416528910
train_109.jsonl
1661871000
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.PrintWriter; public class New { public static void main(String args[]) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int testcases = fs.nextInt(); while(testcases > 0) { testcases--; int n = fs.nextInt(); int xor1 = 0,xor2 = 0; for(int i=0;i<n;i++) { if(i%2==0) { xor1 ^= i; } else { xor2 ^= i; } } int tmp = 0; for(int i=0;i<31;i++) { int num1 = xor1&(1<<i); int num2 = xor2&(1<<i); if(num1 > 0) num1 = 1; if(num2 > 0) num2 = 1; if(num1 != num2) { tmp ^= (int)(1<<i); } } int x = -1; for(int i=1;i<n;i++) { if(tmp != i) { x = i; } } tmp ^= (int)(1<<21); out.print(tmp+" "); for(int i=1;i<n;i++) { if(i == x) { x ^= (int)(1<<21); out.print(x+" "); } else { out.print(i+" "); } } out.println(); } out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["7\n8\n3\n4\n5\n6\n7\n9"]
1 second
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy" ]
52bd5dc6b92b2af5aebd387553ef4076
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
1,500
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
standard output