CF1732E.Location
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays of integers a1,a2,…,an and b1,b2,…,bn. You need to handle q queries of the following two types:
- 1 l r x: assign ai:=x for all l≤i≤r;
- 2 l r: find the minimum value of the following expression among all l≤i≤r: $$\frac{\operatorname{lcm}(a_i, b_i)}{\gcd(a_i, b_i)}.$$
In this problem gcd(x,y) denotes the greatest common divisor of x and y, and lcm(x,y) denotes the least common multiple of x and y.
给你两个整数数组 a1,a2,…,an 和 b1,b2,…,bn。你需要处理 q 个如下两类查询:
- 1 l r x:对所有满足 l≤i≤r 的下标 i,令 ai:=x;
- 2 l r:在所有满足 l≤i≤r 的下标 i 中,求下列表达式的最小值:
gcd(ai,bi)lcm(ai,bi).
输入格式
The first line contains two integers n and q (1≤n,q≤5⋅104) — the number of numbers in the arrays a and b and the number of queries.
The second line contains n integers a1,a2,…,an (1≤ai≤5⋅104) — the elements of the array a.
The third line contains n integers b1,b2,…,bn (1≤bi≤5⋅104) — the elements of the array b.
Then q lines follow, j-th of which starts with an integer tj (1≤tj≤2) and means that the j-th query has type tj.
If tj=1, it is followed by three integers lj, rj, and xj (1≤lj≤rj≤n, 1≤xj≤5⋅104).
If tj=2, it is followed by two integers lj and rj (1≤lj≤rj≤n).
It is guaranteed that there is at least one query of type 2.
第一行包含两个整数 n 和 q(1≤n,q≤5⋅104)—— 分别表示数组 a 和 b 中的元素个数,以及查询次数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤5⋅104)—— 表示数组 a 的元素。
第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤5⋅104)—— 表示数组 b 的元素。
接下来是 q 行,其中第 j 行以一个整数 tj(1≤tj≤2)开头,表示第 j 个查询的类型为 tj。
若 tj=1,则该行后跟三个整数 lj、rj 和 xj(1≤lj≤rj≤n,1≤xj≤5⋅104)。
若 tj=2,则该行后跟两个整数 lj 和 rj(1≤lj≤rj≤n)。
保证至少存在一个类型为 2 的查询。
输出格式
For each query of the second type, output the minimum value of the expression.
对于每个第二类查询,输出该表达式的最小值。
输入输出样例
输入#1
10 10 6 10 15 4 9 25 2 3 5 30 1 2 3 4 6 9 12 15 18 30 2 1 10 1 7 10 9 2 5 10 1 1 6 14 2 4 7 2 3 9 1 2 9 30 2 1 4 2 3 7 2 5 10
输出#1
1 2 12 2 10 5 2
输入#2
4 4 10 2 12 5 1 12 16 1 2 2 4 1 2 3 18 1 2 2 10 2 2 3
输出#2
5 30
说明/提示
In the first example:
- For the first query we can choose i=4. So the value is gcd(4,4)lcm(4,4)=44=1.
- After the second query the array a=[6,10,15,4,9,25,9,9,9,9].
- For the third query we can choose i=9. So the value is gcd(9,18)lcm(9,18)=918=2.
In the second:
- For the first query we can choose i=4. So the value is gcd(1,5)lcm(1,5)=15=5.
- After the second query the array a=[10,18,18,5].
- After the third query the array a=[10,10,18,5].
- For the fourth query we can choose i=2. So the value is gcd(10,12)lcm(10,12)=260=30.
在第一个例子中:
- 对于第一个查询,我们可以选择 i=4。因此该值为 gcd(4,4)lcm(4,4)=44=1。
- 第二个查询之后,数组 a=[6,10,15,4,9,25,9,9,9,9]。
- 对于第三个查询,我们可以选择 i=9。因此该值为 gcd(9,18)lcm(9,18)=918=2。
在第二个例子中:
- 对于第一个查询,我们可以选择 i=4。因此该值为 gcd(1,5)lcm(1,5)=15=5。
- 第二个查询之后,数组 a=[10,18,18,5]。
- 第三个查询之后,数组 a=[10,10,18,5]。
- 对于第四个查询,我们可以选择 i=2。因此该值为 gcd(10,12)lcm(10,12)=260=30。
输入解题思路,AI测评打分。不知道怎么写?