-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Phoenix_and_Beauty.cpp
215 lines (199 loc) · 5.4 KB
/
B_Phoenix_and_Beauty.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
template <int mod>
struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt &operator^=(long long p) { // quick_pow here:3
ModInt res = 1;
for (; p; p >>= 1) {
if (p & 1) res *= *this;
*this *= *this;
}
return *this = res;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
ModInt operator^(long long p) const { return ModInt(*this) ^= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
explicit operator int() const { return x; } // added by QCFium
ModInt operator=(const int p) {
x = p;
return ModInt(*this);
} // added by QCFium
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return ModInt(u);
}
friend std::ostream &operator<<(std::ostream &os, const ModInt<mod> &p) {
return os << p.x;
}
friend std::istream &operator>>(std::istream &is, ModInt<mod> &a) {
long long x;
is >> x;
a = ModInt<mod>(x);
return (is);
}
};
long long mod_pow(long long x, int n, int p) {
long long ret = 1;
while (n) {
if (n & 1) (ret *= x) %= p;
(x *= x) %= p;
n >>= 1;
}
return ret;
}
std::pair<std::vector<long long>, std::vector<int>> get_prime_factor_with_kinds(
long long n) {
std::vector<long long> prime_factors;
std::vector<int> cnt; // number of i_th factor
for (long long i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
prime_factors.push_back(i);
cnt.push_back(0);
while (n % i == 0) n /= i, cnt[(int)prime_factors.size() - 1]++;
}
}
if (n > 1) prime_factors.push_back(n), cnt.push_back(1);
assert(prime_factors.size() == cnt.size());
return {prime_factors, cnt};
}
using mint = ModInt<1000000007>;
// using mint = ModInt<998244353>;
template <typename T>
struct SegmentTree {
using Monoid = typename T::Monoid;
explicit SegmentTree(int n) : SegmentTree(std::vector<Monoid>(n, T::id())) {}
explicit SegmentTree(const std::vector<Monoid> &a) : n(a.size()), sz(1) {
while (sz < n) sz <<= 1;
data.assign(sz << 1, T::id());
std::copy(a.begin(), a.end(), data.begin() + sz);
for (int i = sz - 1; i > 0; --i) {
data[i] = T::merge(data[i << 1], data[(i << 1) + 1]);
}
}
void set(int idx, const Monoid val) {
idx += sz;
data[idx] = val;
while (idx >>= 1)
data[idx] = T::merge(data[idx << 1], data[(idx << 1) + 1]);
}
Monoid get(int left, int right) const {
Monoid res_l = T::id(), res_r = T::id();
for (left += sz, right += sz; left < right; left >>= 1, right >>= 1) {
if (left & 1) res_l = T::merge(res_l, data[left++]);
if (right & 1) res_r = T::merge(data[--right], res_r);
}
return T::merge(res_l, res_r);
}
Monoid operator[](const int idx) const { return data[idx + sz]; }
private:
const int n;
int sz; // sz + 原数组坐标 = 线段树里的编号,1 based
std::vector<Monoid> data;
};
namespace monoid {
template <typename T>
struct RangeMinimumQuery {
using Monoid = T;
static constexpr Monoid id() { return std::numeric_limits<Monoid>::max(); }
static Monoid merge(const Monoid &a, const Monoid &b) {
return std::min(a, b);
}
};
template <typename T>
struct RangeMaximumQuery {
using Monoid = T;
static constexpr Monoid id() { return std::numeric_limits<Monoid>::lowest(); }
static Monoid merge(const Monoid &a, const Monoid &b) {
return std::max(a, b);
}
};
template <typename T>
struct RangeSumQuery {
using Monoid = T;
static constexpr Monoid id() { return 0; }
static Monoid merge(const Monoid &a, const Monoid &b) { return a + b; }
};
} // namespace monoid
void solve() {
int n, k;
std::cin >> n >> k;
std::set<int> s;
std::vector<int> a(n);
for (int &x : a) {
std::cin >> x;
s.insert(x);
}
if (s.size() > k) {
std::cout << -1 << '\n';
return;
}
std::vector<int> ans;
for (int i = 0; i < n; i++) {
for (int x : s) {
ans.push_back(x);
}
ans.push_back(1);
}
int m = ans.size();
std::cout << m << '\n';
for (int x : ans) std::cout << x << ' ';
std::cout << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--) solve();
return 0;
}