1
+ /*
2
+ author: Ali
3
+ Email: AliGhanbariCs@gmail.com
4
+ GitHub: https://github.com/AliBinary
5
+ created: 19.04.2024 13:58:11
6
+ */
7
+ #include < bits/stdc++.h>
8
+ using namespace std ;
9
+ #define fast_io ios::sync_with_stdio (false ), cin.tie(0 ), cout.tie(0 );
10
+
11
+ #define endl ' \n '
12
+ #define sep ' '
13
+ typedef long long ll;
14
+ typedef long double ld;
15
+ typedef string str;
16
+
17
+ // pairs
18
+ typedef pair<ld, ld> pdd;
19
+ typedef pair<ll, ll> pll;
20
+ typedef pair<int , int > pii;
21
+ typedef pair<pii, int > ppi;
22
+ typedef pair<int , pii> pip;
23
+ typedef pair<pii, pii> ppp;
24
+ #define F first
25
+ #define S second
26
+ #define mp make_pair
27
+
28
+ #define tcT template <class T
29
+ tcT > using V = vector<T>;
30
+
31
+ // vectors
32
+ #define sz (x ) int ((x).size())
33
+ #define bg (x ) begin(x)
34
+ #define all (x ) bg(x), end(x)
35
+ #define rall (x ) x.rbegin(), x.rend()
36
+ #define sor (x ) sort(all(x));
37
+ #define sor_ (x ) sort(rall(x));
38
+ #define rsz resize
39
+ #define ins insert
40
+ #define pb push_back
41
+ #define eb emplace_back
42
+ #define ft front ()
43
+ #define bk back ()
44
+ #define cpresent (container, element ) (find(all(container), element) != container.end())
45
+ // sets
46
+ #define present (container, element ) (container.find(element) != container.end())
47
+
48
+ #define lb lower_bound
49
+ #define ub upper_bound
50
+ tcT > int lwb (V<T> &a, const T &b) { return int (lb (all (a), b) - bg (a)); }
51
+ tcT > int upb (V<T> &a, const T &b) { return int (ub (all (a), b) - bg (a)); }
52
+
53
+ // loops
54
+ #define FOR (i, a, b ) for (int i = (a); i < (b); ++i)
55
+ #define F0R (i, b ) FOR(i, 0 , b)
56
+ #define ROF (i, a, b ) for (int i = (b)-1 ; i >= (a); --i)
57
+ #define R0F (i, b ) ROF(i, 0 , b)
58
+ #define rep (n ) FOR(_, 0 , n)
59
+ #define each (x, a ) for (auto &x : a)
60
+ #define tr (container, it ) \
61
+ for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
62
+
63
+ // debug
64
+ #define debug (x ) cerr << #x << ' =' << (x) << endl;
65
+ #define debugp (x ) cerr << #x << " = {" << (x.first) << " , " << (x.second) << " }" << endl;
66
+ #define debug2 (x, y ) cerr << " {" << #x << " , " << #y << " } = {" << (x) << " , " << (y) << " }" << endl;
67
+ #define debugv (v ) \
68
+ { \
69
+ cerr << #v << " : " ; \
70
+ for (auto x : v) \
71
+ cerr << x << ' ' ; \
72
+ cerr << endl; \
73
+ }
74
+ #define wall cout << " ----------------------------------------\n " ;
75
+ #define kill (x ) \
76
+ { \
77
+ cout << x << endl; \
78
+ return ; \
79
+ }
80
+
81
+ // bitwise ops
82
+ constexpr int pct (int x) { return __builtin_popcount (x); } // # of bits set
83
+ constexpr int bits (int x) { return x == 0 ? 0 : 31 - __builtin_clz (x); } // floor(log2(x))
84
+ constexpr int p2 (int x) { return 1 << x; }
85
+ constexpr int msk2 (int x) { return p2 (x) - 1 ; }
86
+ ll cdiv (ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
87
+ ll fdiv (ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down
88
+ tcT > bool ckmin (T &a, const T &b) { return b < a ? a = b, 1 : 0 ; } // set a = min(a,b)
89
+ tcT > bool ckmax (T &a, const T &b) { return a < b ? a = b, 1 : 0 ; } // set a = max(a,b)
90
+ tcT > void remDup (vector<T> &v) { sort (all (v)), v.erase (unique (all (v)), end (v)); } // sort and remove duplicates
91
+
92
+ bool cmp1 (pair<ll, pll> i1, pair<ll, pll> i2)
93
+ {
94
+ return (i1.F < i2.F );
95
+ }
96
+ bool cmp2 (pair<ll, pll> i1, pair<ll, pll> i2)
97
+ {
98
+ return (i1.S .F < i2.S .F );
99
+ }
100
+
101
+ const int inf = std::numeric_limits<int >::max();
102
+ const ll INF = std::numeric_limits<ll>::max();
103
+ void solve ();
104
+
105
+ int main ()
106
+ {
107
+ fast_io;
108
+
109
+ int t = 1 ;
110
+ cin >> t;
111
+ while (t--)
112
+ {
113
+ solve ();
114
+ }
115
+
116
+ return 0 ;
117
+ }
118
+
119
+ void solve ()
120
+ {
121
+ ll n, k;
122
+ cin >> n >> k;
123
+ V<pair<ll, pll>> a (n);
124
+ V<ll> b (n);
125
+ int i = 0 ;
126
+ each (x, a)
127
+ {
128
+ cin >> x.S .F ;
129
+ x.F = i++;
130
+ }
131
+ sort (a.begin (), a.end (), cmp2);
132
+ each (x, b)
133
+ {
134
+ cin >> x;
135
+ }
136
+ sor (b);
137
+ FOR (i, 0 , n)
138
+ {
139
+ a[i].S .S = b[i];
140
+ }
141
+ sort (a.begin (), a.end (), cmp1);
142
+
143
+ each (x, a)
144
+ {
145
+ cout << x.S .S << sep;
146
+ }
147
+ cout << endl;
148
+ }
149
+
150
+ /* stuff you should look for
151
+ * int overflow, array bounds
152
+ * special cases (n=1?)
153
+ * do smth instead of nothing and stay organized
154
+ * WRITE STUFF DOWN
155
+ * DON'T GET STUCK ON ONE APPROACH
156
+ */
0 commit comments