mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 15:58:48 +00:00
C - Fishingprince Plays With Array
https://codeforces.com/contest/1696/submission/161823627
This commit is contained in:
parent
4f89724f85
commit
422543715d
58
Codeforces/1696/C/C.cpp
Normal file
58
Codeforces/1696/C/C.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 5e4 + 5;
|
||||
|
||||
int t, n, m, k, a[N], b[N];
|
||||
|
||||
void expand(int *arr, int n, int m, std::vector<std::pair<long long, long long>> &vec) {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
long long x = arr[i],
|
||||
cnt = 1;
|
||||
|
||||
while (x % m == 0) {
|
||||
x /= m;
|
||||
cnt *= m;
|
||||
}
|
||||
|
||||
if (!vec.empty() && vec.rbegin()->first == x) {
|
||||
vec.rbegin()->second += cnt;
|
||||
} else {
|
||||
vec.push_back(std::make_pair(x, cnt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
std::vector<std::pair<long long, long long>> va, vb;
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1, x; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
cin >> k;
|
||||
|
||||
for (int i = 1; i <= k; i++) {
|
||||
cin >> b[i];
|
||||
}
|
||||
|
||||
expand(a, n, m, va);
|
||||
expand(b, k, m, vb);
|
||||
|
||||
cout << (va == vb ? "Yes" : "No") << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user