CF Global Round 21 C

题意:

给定一个N个数的置换a,和k个数的置换B,以及一个数M,每次可以对A进行一下操作:

1.若ai可以被m整除,则可以将ai替换为m个ai/m

2.若存在连续m个ai完全相等,ze可以将这m个数替换为一个m*ai

问a经过若干操作后是否能变为b

思路:

显然我们发现操作12是可逆的,所以这个题目可以变成:问对ab操作后是否能得到同一序列,我们只需要不断的对ab做1操作展开,最后判断展开是否相等即可,需要注意的是这里展开要合并压缩,直接展开会mle

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int inf = 1e9 + 9;
const ll INF = 1e18l;
/*
priority_queue<int> big_heep;
priority_queue<int,vector<int>,greater<int> > small_heep;
struct cmp{//if return true,it means that the number in the left was smaller than the right one
		bool  operator ()  (int  a,int  b){
	   }
};
 */
ll a1[300005], a2[300005], num1[300005], num2[300005], b1[300005], b2[300005];
ll zz(ll num,ll z) {
	ll x = 1;
	for (int i = 1;i <= num;i++) x *= z;
	return x;
}
void work() {
	ll n1, n2, z, m1, m2;
	m1 = m2 = 0;
	cin >> n1 >> z;
	memset(num1, 0, sizeof(ll) * (n1 + 4));
	memset(b1, 0, sizeof(ll) * (n1 + 4));
	for (int i = 1;i <= n1;i++) {
		cin >> a1[i];
		ll t = a1[i];
		ll num = 0;
		while (t % z==0) {
			num ++;
			t /= z;
		}
		num = zz(num,z);
		if (t == a1[i]) {
			if (m1 == 0) {
				b1[++m1] = a1[i];
				num1[m1]++;
			}
			else {
				if (t != b1[m1]) {
					b1[++m1] = t;
					num1[m1] ++;
				}
				else num1[m1] ++;
			}
		}
		else {
			if (m1 == 0) {
				b1[++m1] = t;
				num1[m1] += num;
			}
			else {
				if (t != b1[m1]) {
					b1[++m1] = t;
					num1[m1] += num;
				}
				else num1[m1] += num;
			}
		}
	}
	cin >> n2;
	memset(num2, 0, sizeof(ll) * (n2 + 4));
	memset(b2, 0, sizeof(ll) * (n2 + 4));
	for (int i = 1;i <= n2;i++) {
		cin >> a2[i];
		ll t = a2[i];
		ll num = 0;
		while (t % z == 0) {
			num ++;
			t /= z;
		}
		num = zz(num, z);
		if (t == a2[i]) {
			if (m2 == 0) {
				b2[++m2] = a2[i];
				num2[m2]++;
			}
			else {
				if (t != b2[m2]) {
					b2[++m2] = t;
					num2[m2] ++;
				}
				else num2[m2] ++;
			}
		}
		else {
			if (m2 == 0) {
				b2[++m2] = t;
				num2[m2]+=num;
			}
			else {
				if (t != b2[m2]) {
					b2[++m2] = t;
					num2[m2] += num;
				}
				else num2[m2] += num;
			}
		}
	}
	if (m1 != m2) {
		cout << "NO\n";
		return;
	}
	for (int i = 1;i <= m1;i++) {
		if (b1[i] != b2[i]) {
			cout << "NO\n";
			return;
		}
	}
	cout << "YES\n";
	return;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	while (t--) {
 
		work();
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值