比赛 4043级NOIP2022欢乐赛3rd 评测结果 WAWWTTTTTT
题目名称 GCD和LCM问题 最终得分 10
用户昵称 该账号已注销 运行时间 19.070 s
代码语言 C++ 内存使用 5.04 MiB
提交时间 2022-11-04 19:29:38
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[50010], b[50010], c[50010];

int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

int main() {
	freopen("gcdlcm.in", "r", stdin);
	freopen("gcdlcm.out", "w", stdout);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		int p = gcd(a[i], b[i]);
		c[i] = a[i] * b[i] / (p * p);
	}
	for (int i = 1; i <= q; i++) {
		int t;
		cin >> t;
		int l, r;
		if (t == 1) {
			int x;
			cin >> l >> r >> x;
			for (int j = l; j <= r; j++) {
				a[j] = x;
				int p = gcd(a[j], b[j]);
				c[j] = a[j] * b[j] / (p * p);
			}
		} else {
			cin >> l >> r;
			int ans = 0x3f3f3f3f;
			for (int j = l; j <= r; j++) {
				ans = min(ans, c[j]);
			}
			cout << ans << endl;
		}
	}
	return 0;
}