Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.*; import java.util.*; public class MainClass { public static void main(String[] args)throws IOException { Reader in = new Reader(); int t = in.nextInt(); StringBuilder stringBuilder = new StringBuilder(); while (t-- > 0) { int n = in.nextInt()...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { // TODO Auto-generated meth...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
//package cf; import java.io.*; import java.util.*; public class T_class { static int m=2147483647;///this is 2^32 -1 (is prime number) and should be used for hashing static int p=1000000007; static int max=(int)2e3+10; static boolean prime[]=new boolean[max+5]; static int dp[][]=new int[(int)max]...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for __ in range(int(input())): n = int(input()) # a = [-1]*(n+1) b = [-1]*(2*n) a = [int(x) for x in input().split()] m1 = {} for i in range(n): m1[a[i]] = 1 b[2*i] = a[i] for i in range(1,2*n,2): k = a[i//2] while k in m1: k += 1 b[i] = k m1[k]=1 #print(m1) f=0 for x in b: if x > 2*n: f=1...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc, ca = 0; cin >> tc; while (tc--) { int n, el; vector<int> b; vector<int> baki; map<int, int> m1; map<int, int> m2; cin >> n; for (int i = 0; i < ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; public class realfast implements Runnable { private static final int INF = (int) 1e9; long in= (long)Math.pow(10,9); public void solve() throws IOException { int t ...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import sys input = sys.stdin.readline t = int(input()) import bisect for _ in range(t): n = int(input()) a = list(map(int,input().split())) b = [0 for _ in range(2*n)] for x in a: b[x-1] = 1 c = [] for i in range(2*n): if b[i] == 0: c.append(i+1) try: d = [] for x in a: bi = bi...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.HashSet; import java.util.InputMismatchException; import java.util.TreeSet; /** * @author Mubtasim Shahriar */ public class ResPer ...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for _ in range(int(input())): n = int(input()) l = [*map(int,input().split())] s = set() s1 = set(l) for i in range(1,2*n + 1): if(i not in s1): s.add(i) ans = [] for i in range(n): ans.append(l[i]) for j in range(l[i] + 1, 2 * n + 1,1): if(j i...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; long long int fast_expo(long long int x, long long int p) { if (p == 0) return 1; else if (p % 2 == 0) { long long int t = fast_expo(x, p / 2) % 1000000007; return (t * t) % 1000000007; } else return (x * (fast_expo(x, p - 1)) % 1000000007) % 100000000...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t=int(input()) for _ in range(t): n=int(input()) b=list(map(int, input().split() )) s=set(b) ans=[] possible=True for x in b: y=x+1 while y<=2*n: if y not in s: break y=y+1 if y>2*n: possible=False break s.add(y) ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.*; import java.util.*; public class MyClass { public static void main(String args[]) { FastReader sc = new FastReader(); //For Fast IO //func f = new func(); //Call func for swap , permute, upper bound and for sort. StringBuilder sb = new StringBuilder(); ...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for nt in range(int(input())): n=int(input()) b=list(map(int,input().split())) d=set(b) ansflag=0 ans=[] d1={} for i in range(n): ans.append(b[i]) k=1 flag=0 #print (ans) while True: if (b[i]+k)>2*n: flag=1 break if b[i]+k not in d and b[i]+k not in d1: ans.append(b[i]+k) d1[b[i]+...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.math.*; public class Codeforces { public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); int t=s.nextInt(); for(int i=0;i<t...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; unordered_set<int> us; for (int i = 0; i < n; i++) { cin >> arr[i]; us.insert...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read integers get_int = lambda: int(sys.stdin.readline()) #to print fast #pt = lambda x: sys.stdout.write(str(x)+'\n') #------...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) ans = [0 for i in range(2*n)] visited = [False for i in range(2*n)] ind = 0 for i in range(0,2*n,2): ans[i] = arr[ind] visited[arr[ind]-1]=True ind+=1 # print(visited) for i in ran...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
whatever=int(input()) for i in range (whatever) : k=int(input()) bs=list(map(int,input().split())) a=[0]*2*k avail=[] for t in range (1,(2*k)+1) : if t not in bs : avail.append(t) avail=sorted(avail) for l in range (0,(2*k),2) : a[l]=bs[int(l/2)] flag=0 ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int b[105], vis[205]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int pd = 0; memset(vis, 0, sizeof(vis)); int maxx = 0; for (int i = 0; i < n; i++) { scanf("%d", &b[i]); maxx = max(maxx, b[i]); ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import bisect import collections t = int(input()) for test in range(t): canDo = True n = int(input()) # elements in sequence b = [] a = list(range(1,2*n+1)) for i in input().split(): b.append(int(i)) a.remove(int(i)) a.sort() c = [] for i, elem in enumerate(b): p...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for _ in " "*int(input()): a=int(input()) if a==1: z=int(input()) if z==1:print("1 2") else:print(-1) continue b=list(map(int,input().split())) if 1 not in b or 2*a in b:print(-1);continue c=[ i for i in range(1,(2*a)+1) if i not in b] r=[] for i in range(a): ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.util.*; import java.io.*; import java.math.*; public class Main7 { static class Pair { int x; int y; int z; Pair(int x, int y,int z) { this.x=x; this.y=y; this.z=z; } } static int mod=1000000007; public static int[] sort(int[] a) { int n=a.length; ArrayList<Integer> ar=new Arr...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; vector<long long> vprime; void SieveOfEratosthenes(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); 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 p = 2; p ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.*; public class ProblemC { public static InputStream inputStream = System.in; public static OutputStream outputStream = System.out; public static void main(String[] args) { Scanner scanner = new...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t=int(input()) for _ in range(t): n=int(input()) b=list(map(int,input().split())) s=set(range(2 * n + 1)) s.remove(0) l=[201]*(2*n) flag = True for i in range(0, 2*n, 2): l[i] = b[i//2] s.remove(l[i]) for i in range(1, 2*n, 2): for num in s: if num > l...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> const int N = 1e6; const double eps = 0.00000001; const long long mod = 1e9 + 7; using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t, n, a[100], b[100], i, j, f; cin >> t; while (t--) { cin >> n; int temp[201] = {0}; for (i = 0; i < n; i++) { cin >> a[i]; temp[a[i]]++; } for (i = 0; i < n; i++) { f = 0; j = a[i] + 1; while (j <= 2...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.*; import java.util.ArrayList; import java.util.List; public class Solution { public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(System.out); ...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t=int(input()) s=[] for njj in range(0,t): n=int(input()) b=list(map(int,input().split( ))) if 1 not in b or 2*n in b: s.append([-1]) else: a=[] for i in b: g=1 f=i while i+g in a or i+g in b : g+=1 if i+g>2*n: ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; map<long long, long long> mp; for (long long i = 0; i < n; i++) { cin >> arr[i]; mp[arr[...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> v(2 * n + 1, 0), A; for (int i = 0; i < n; i++) { int x; cin >> x; v[x] = 1; A.push_back(x); } int justice = 0; for (int i = 1; i <= 2 * n; i++) { if (justice < 0 && v[i] == 1) { cout << -1 ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
from sys import exit from bisect import bisect def iis(): return map(int, input().split()) def ii(): return int(input()) def liis(): return list(map(int, input().split())) t = ii() for _ in range(t): n = ii() b = liis() todos = [] duplas = [] for i in range(1, 2*n+1): if i not in b: todos.append(i) flag = ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
from collections import * for i in range(int(input())): n, a, ans = int(input()), list(map(int, input().split())), [] mem = Counter(a) for j in range(n): ans.append(a[j]) for k in range(a[j] + 1, 2 * n + 1): if not mem[k]: ans.append(k) mem[k] = ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t = int(input()) for _ in range(t): n = int(input()) b = list(map(int, input().split())) ansls=[0]*(2*n) used=set(b) flag=True for i in range(n): ansls[2*i]=b[i] for j in range(b[i]+1, 2*n+1): if not j in used: ansls[2*i+1]=j used.add(j...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t = int(input()) for x in range(t): n = int(input()) b = list(map(int, input().split())) numbers_used = [False for i in range(2*n)] a = [] for i in b: numbers_used[i-1] = True for i in b: a.append(i) for j in range(i, 2*n): if numbers_used[j]==False: ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for _ in range(int(input())): n, b = int(input()), list(map(int, input().split())) d = {e: True for e in range(1, 2*n + 1)} a = [0] * (2 * n) for i in range(n): a[2*i] = b[i] d[b[i]] = False ok = True for i in range(1, 2*n, 2): e = a[i-1] + 1 while e <= 2*n: ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
n = int(input()) for i in range(n): lena = int(input()) arr = list(map(int, input().split())) rem = [j for j in list(range(1, 2*lena+1)) if j not in arr] counter = 0 final = [] for j in range(lena): counter2 = 0 for k in range(arr[j], 2*lena+1): if k in rem: ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t = int(input()) for _ in range(t): n = int(input()) b = list(map(int, input().split())) for i in range(n): b[i] -= 1 # print("b: ", b) used = [False for _ in range(2*n)] for i in range(n): used[b[i]] = True ans = [0 for i in range(2*n)] for i in range(n): ans[2*i] = b[i] result = True for i in range(n...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.util.*; import java.lang.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } ...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int,input().split())) b = set(range(1,n*2+1)) b = b - set(a) b = list(b) f = 0 ans = [] for i in a: found = 0 j = 0 while j < len(b): if b[j] > i: found = 1 ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 100 + 10; int n; int b[maxn]; int ans[2 * maxn]; void solve() { cin >> n; map<int, int> m; m.clear(); for (int i = 1; i <= n; i++) { cin >> b[i]; m[b[i]] = 1; ans[2 * i - 1] = b[i]; } for (int i = 1; i <= ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t=int(input()) for _ in range(t): n=int(input()) a=[i for i in range(1,2*n+1)] m=[int(i) for i in input().split()] l=[] for e in m: k=e l.append(k) while(True): e=e+1 if e not in m and e not in l: l.append(e) break ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for _ in range(int(input())): n = int(input()) b = list(map(int,input().split())) used = [False]*( (2*n)+1) a = [None]*(2*n) possible=True for bi in b: used[bi] = True for i in range(2*n): if i%2==0: a[i] = b[i//2] else: no = a[i-1]+1 while...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int main() { bool u = 0, n = 0, z = 0; int a, b, c[100000] = {}, p, d, q = 1, s = 1; cin >> a; for (int i = 0; i < a; i++) { cin >> b; p = b * 2; s = 1; for (int i = 0; i <= (b * 2 - 2); i += 2) cin >> c[i]; for (int i = 0; i <= (b * 2 - 2); i +=...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t = int(input()) for test in range(t): n = int(input()) b = [int(i) for i in input().split()] def solve(): def minimal(v): for i in perm: if i > v: return perm.pop(perm.index(i)) return v perm = list(range(1, n * 2 + 1)) for...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Comparator; import java.util.Scanner; import java.util.Arrays; import java.util.TreeSet; import java.util.StringTokenizer; public class vk18 { public static void main(String[] stp) throws Exception { ...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public cla...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def MAP2():return map(float,input().split()) def LIST(): return list(map(int, input().split())) def STRING(): return input() import string import sys from heapq import heappop , heappush from bisect import * from...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t = int(input()) solutions = [] for i in range(t) : n = int(input()) string = str(input()) st = string.split() lst = [] for j in range(n) : lst.append(int(st[j])) solution = [] for j in range(n) : solution.append(lst[j]) number = lst[j] ok = 0 while ok...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [] d = 0 for i in range(1, 2*n+1): if i not in a: b.append(i) b.sort() c = [] i = 0 j = 0 while(len(b) > 0): if(b[-1] < a[i]): d = 1 break ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
I=input for _ in[0]*int(I()): n=2*int(I());a=n*[0];b=a[::2]=*map(int,I().split()),;c={*range(1,n+1)}-{*b};i=1 try: for x in b:z=a[i]=min(y for y in c if x<y);c-={z};i+=2 except:a=-1, print(*a)
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
from math import * # from sys import stdin,stdout def binarySearch(arr,x,i): l=i r=len(arr)-1 while l <= r: mid = (l + r)//2; if arr[mid] == x: return mid elif arr[mid] < x: l = mid + 1 else: r = mid - 1 return -1 def js(arr,x): l=0 r=len(arr)-1 ans=-1 while(l<=r): m=(l+r)//2 if(ar...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.util.*; import java.io.*; public class Asd { static Scanner s=new Scanner(System.in); static PrintWriter w=new PrintWriter(System.out); public static void main(String args[]) { int t=s.nextInt(); while(t-->0) { solve(); } w.close(); } public static void...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.util.*; public class Solution{ public static void main(String args[]){ Scanner in=new Scanner (System.in); int t=in.nextInt(); while(--t>=0){ int n=in.nextInt(); int a[]=new int[n]; int b[]=new int[2*n]; HashSet<Integer> hset=new Ha...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.util.*; import java.lang.*; import java.io.*; public class Main { /* HashMap<> map=new HashMap<>(); TreeMap<> map=new TreeMap<>(); map.put(p,map.getOrDefault(p,0)+1); for(Map.Entry<> mx:map.entrySet()){ int v=mx.getValue(),k=mx.getKey(); }for (int i = 1; i <= 1000; i++) ...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.HashSet; import java.io.Writer; import java.io.OutputStreamWr...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); M: while (t-- > 0) { int n = scn.nextInt(), B_ARR[] = new int[n + 1]; HashSet<Integer> set = new HashSet<>(); for (int i = 1; i <= n; i++) { B_ARR...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.*; import java.util.*; import java.math.*; /** * Built using CHelper plug-in * Actual solution is at the top */ public class RestoringPermutation { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputRe...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t = int(input()) import heapq for _ in range(t): n = int(input()) B = list(map(int, input().split())) if 1 not in set(B): print(-1) continue d = {} A = [0]*(2*n) for i in range(n): A[2*i] = B[i] d[B[i]] = 2*i+1 #print(id) flag = True ids = [] heapq...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import math from collections import Counter for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) ll=[] s=list(range(1,n+1)) for i in l: ll.append(i) if i+1 not in ll and i+1 not in l: ll.append(i+1) else: j=i+2 whil...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
from bisect import * for t in range(int(input())): n=int(input()) b=list(map(int,input().split())) f=0 c=set(b) d=[] for i in range(1,2*n+1): if i not in c: d.append(i) a=[] for i in range(n): a.append(b[i]) x=bisect_left(d,b[i]) if x==len(d): ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int t= in.nextInt(); while(t-- > 0) { ...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
for _ in range(int(input())): n = int(input()) dic = {} for i in range(1,2*n+1): dic[i] = 0 arr = list(map(int,input().split())) flag = 0 for i in range(n): if arr[i]>=2*n: flag = 1 dic[arr[i]] = 1 l = [0]*(2*n) count = 0 for i in range(0,2*n,2): ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import sys import copy input=sys.stdin.buffer.readline t=int(input()) while t: t-=1 n=int(input()) arr=list(map(int,input().split())) arr1=copy.deepcopy(arr) arr1.sort() if arr1[0]==1: if max(arr)+1<=2*n: ans=[] for i in range(n): ans.append(arr[i]) for j in range(arr[i]+1,2*n+1): if j not i...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int t, n; void solve() { cin >> n; int b[n]; bool foundMin = false; bool foundMax = false; for (int i = 0; i < n; i++) { cin >> b[i]; if (b[i] == 1) foundMin = true; if (b[i] == n * 2) foundMax = true; } if (!foundMin || foundMax) { cout << "-1...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; bool compare(const pair<string, string>& i, const pair<string, string>& j) { if (i.first != j.first) return i.first < j.first; else return i.second < j.second; } vector<long long> factorize(long long n) { vector<long long> v; for (long long i = 2; i * i <= n...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int a[101]; bool c[201]; vector<int> b[101]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; memset(c, false, sizeof(c)); for (int i = 0; i < n; i++) { b[i].clear...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.*; import java.util.*; public class Main { static Scanner sc = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); static void solve() throws Exception { int n = sc.nextInt(), arr[] = new int[2 * n]; TreeSet<Integer> st = new TreeSet<>(); for (int i = 1; i <= 2 * n;...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
t = int(input()) for _ in range(t): n = int(input()) B = list(map(int, input().split())) cands = [True] * (2 * n) for b in B: cands[b - 1] = False ret = [] for b in B: ret.append(b) for i in range(2 * n): if b < i + 1 and cands[i]: ret.append(i + 1) cands[i] = False ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, j, k, n, x, y, x1, y1, x2, y2, p, arr[1000], b[2000], l; cin >> t; while (t--) { cin >> n; j = 0; long long int flag = 0, flag1 = 1; for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] > n) { j++; ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
T=int(input()) for _ in range(T): a=int(input()) A=list(map(int,input().split())) DP=[0 for i in range((2*a)+1)] flag=0 for i in A: if(i>(2*a)): flag=1 else: DP[i]=1 if(flag==1): print(-1) continue else: mv=a B=[] ...
PYTHON3
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int arr[105]; unordered_set<int> used; bool fl = 1; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> arr[i]; used.insert(arr[i]); } vector<int> v; for (int i = 0; i < n; ++i) { ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int b[n]; int ans[2 * n]; for (long long i = 0; i < n; i++) cin >> b[i]; set<int> a; for (long long i = 0; i < 2 * n; ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class CodeForce { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(Sy...
JAVA
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int arr[n]; vector<bool> brr(2 * n + 1, 0); brr[0] = 1; for (int i = 0; i < n; i++) { cin >> arr[i]; brr[arr[i]] = 1; } vector<int> v(n); bool flag = 1, flag2 = 0; for (int i = 0; i < n; i++) { flag2 = 0; f...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; set<int> s; for (int i = 1; i <= 2 * n; i++) s.insert(i); vector<int> b(n + 1); vector<int> a(2 * n + 1, 0); ...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), b(2 * n); multiset<int> m; for (size_t i = 0; i < 2 * n; ++i) m.insert(i + 1); for (a...
CPP
1315_C. Restoring Permutation
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
2
9
def bubbleSort(arr): n = len(arr) # Traverse through all array elements for i in range(n): # Last i elements are already in place for j in range(0, n-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater # than ...
PYTHON3
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; using LL = long long; namespace _buff { const size_t BUFF = 1 << 19; char ibuf[BUFF], *ib = ibuf, *ie = ibuf; char getc() { if (ib == ie) { ib = ibuf; ie = ibuf + fread(ibuf, 1, BUFF, stdin); } return ib == ie ? -1 : *ib++; } } // namespace _buff LL read() { ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> namespace IO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; inline char myGetchar() { static char buf[IN_BUF], *ps = buf, *pt = buf; if (ps == pt) { ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin); } return ps == pt ? EOF : *ps++; } template <typename T> inline bool read(...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int maxN = 223456; const int P = 998244353; int n, m, rnk; i64 base[maxN], p[maxN], dp[60][60][2]; int cnt[maxN], ans[maxN]; void dfs1(int d, i64 x) { if (d == rnk) { cnt[__builtin_popcountll(x)]++; } else { dfs1(d + 1, x); dfs1(...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 200010; const int M = 60; inline int add(int u, int v) { return (u += v) >= MOD ? u - MOD : u; } inline int sub(int u, int v) { return (u -= v) < 0 ? u + MOD : u; } inline int mul(int u, int v) { return (long long)u * v % MOD; } inli...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> template <class T> inline void read(T &x) { x = 0; register char c = getchar(); register bool f = 0; while (!isdigit(c)) f ^= c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } const int N = 60, mod = 998244353; int n, m, k, t, c[N]; lo...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> namespace { using u64 = uint64_t; static const int MOD = 998244353; struct LargeSolver { LargeSolver(int r_, int m_, std::vector<u64> &&b_) : r{r_}, m{m_}, b{std::move(b_)}, count(m + 1), result(m + 1) { dfs_large(0, 0, 0); int power_of_two = 1; for (int i = 0; i < m - r; ++...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> #pragma GCC target("popcnt,sse4.2") using namespace std; const int mod = 998244353; inline int add(int a, int b) { if ((a += b) >= mod) a -= mod; return a; } inline int dec(int a, int b) { if ((a -= b) < 0) a += mod; return a; } inline int mult(int a, int b) { long long t = 1ll * a * ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; void exgcd(int a, int b, int& x, int& y) { if (!b) { x = 1, y = 0; } else { exgcd(b, a % b, y, x); y -= (a / b) * x; } } int inv(int a, int n) { int x, y; exgcd(a, n, x, y); return (x < 0) ? (x + n) : (x); } const int Mod = 998244353; template <const...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; const int mo = 998244353; int n, m, s1, cnt[65536]; long long a[55], x, ans[55]; void insert(long long x) { for (int i = (int)(m - 1); i >= (int)(0); i--) if (x & (1ll << i)) if (!a[i]) { a[i] = x; break; } else x ^= a[i]; } int Cou...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; inline void add(int &x, int y) { (x += y) >= mod ? x -= mod : 0; } inline int pl(int x, int y) { return (x += y) >= mod ? x - mod : x; } inline int kpow(int a, int b) { int s = 1; for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) s = 1l...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b) { if (!b) return 1; long long k = mul(a, b / 2); if (b & 1) return k * k % 998244353 * a % 998244353; return k * k % 998244353; } int n, m, k; long long b[64], arr[64], C[64][64], w[64][64], ans[64]; long long val; bool mark[6...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; const int mn = 1e5 + 10; const int mm = 53; const long long mod = 998244353; long long basis[mm]; int m; bool add(long long x) { for (int i = m - 1; i >= 0; i--) if ((x >> i) & 1) { if (basis[i]) x ^= basis[i]; else { basis[i] = x; ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int n, m; vector<long long> bs; int cnt[(1 << 16) + 1]; long long inv2 = (998244353 + 1) / 2; int popcount(long long x) { return cnt[x & 65535] + cnt[x >> 16 & 65535] + cnt[x >> 32 & 65535] + cnt[x >> 48 & 65535]; } bool add(long long x...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> template <class T> inline void read(T &res) { res = 0; bool bo = 0; char c; while (((c = getchar()) < '0' || c > '9') && c != '-') ; if (c == '-') bo = 1; else res = c - 48; while ((c = getchar()) >= '0' && c <= '9') res = (res << 3) + (res << 1) + (c - 48); if (...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; const int P = 998244353, N = 100; int n, m, g[N], k, C[N][N], w[N][N], ans[N], cnt; long long a[N], b[N], c[N], x; int ksm(int a, int b) { int ans = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) ans = 1ll * ans * a % P; return ans; } void insert(long long ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using vc = vector<t>; template ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == '-') f = -1; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + ch - 48; } return x * f; } const int mxN = 1 << 19; const int mxM = 53; const ...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } inline int read() { int s = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '...
CPP
1336_E2. Chiori and Doll Picking (hard version)
This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati...
2
11
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int n, m; vector<long long> bs, todo; int cnt[(1 << 16) + 1]; long long inv2 = (mod + 1) / 2; int popcount(long long x) { return __builtin_popcountll(x); } long long getp(long long x) { return 63 - __builtin_clzll(x); } bool add(long long x) { f...
CPP