CF1732E.Location

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two arrays of integers a1,a2,…,ana_1, a_2, \ldots, a_n and b1,b2,…,bnb_1, b_2, \ldots, b_n. You need to handle qq queries of the following two types:

  • 11 ll rr xx: assign ai:=xa_i := x for all l≤i≤rl \leq i \leq r;
  • 22 ll rr: find the minimum value of the following expression among all l≤i≤rl \leq i \leq r: $$\frac{\operatorname{lcm}(a_i, b_i)}{\gcd(a_i, b_i)}.$$

In this problem gcd⁡(x,y)\gcd(x, y) denotes the greatest common divisor of xx and yy, and lcm⁡(x,y)\operatorname{lcm}(x, y) denotes the least common multiple of xx and yy.

给你两个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n 和 b1,b2,…,bnb_1, b_2, \ldots, b_n。你需要处理 qq 个如下两类查询:

  • 11 ll rr xx:对所有满足 l≤i≤rl \leq i \leq r 的下标 ii,令 ai:=xa_i := x;
  • 22 ll rr:在所有满足 l≤i≤rl \leq i \leq r 的下标 ii 中,求下列表达式的最小值:

    lcm⁡(ai,bi)gcd⁡(ai,bi).\frac{\operatorname{lcm}(a_i, b_i)}{\gcd(a_i, b_i)}.

本题中,gcd⁡(x,y)\gcd(x, y) 表示 xx 与 yy 的最大公约数,lcm⁡(x,y)\operatorname{lcm}(x, y) 表示 xx 与 yy 的最小公倍数。

输入格式

The first line contains two integers nn and qq (1≤n,q≤5⋅1041 \leq n, q \leq 5 \cdot 10^4) — the number of numbers in the arrays aa and bb and the number of queries.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤5⋅1041 \leq a_i \leq 5 \cdot 10^4) — the elements of the array aa.

The third line contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤5⋅1041 \leq b_i \leq 5 \cdot 10^4) — the elements of the array bb.

Then qq lines follow, jj-th of which starts with an integer tjt_j (1≤tj≤21 \leq t_j \leq 2) and means that the jj-th query has type tjt_j.

If tj=1t_j = 1, it is followed by three integers ljl_j, rjr_j, and xjx_j (1≤lj≤rj≤n1 \leq l_j \leq r_j \leq n, 1≤xj≤5⋅1041 \leq x_j \leq 5 \cdot 10^4).

If tj=2t_j = 2, it is followed by two integers ljl_j and rjr_j (1≤lj≤rj≤n1 \leq l_j \leq r_j \leq n).

It is guaranteed that there is at least one query of type 22.

第一行包含两个整数 nn 和 qq(1≤n,q≤5⋅1041 \leq n, q \leq 5 \cdot 10^4)—— 分别表示数组 aa 和 bb 中的元素个数,以及查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤5⋅1041 \leq a_i \leq 5 \cdot 10^4)—— 表示数组 aa 的元素。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤5⋅1041 \leq b_i \leq 5 \cdot 10^4)—— 表示数组 bb 的元素。

接下来是 qq 行,其中第 jj 行以一个整数 tjt_j(1≤tj≤21 \leq t_j \leq 2)开头,表示第 jj 个查询的类型为 tjt_j。

若 tj=1t_j = 1,则该行后跟三个整数 ljl_j、rjr_j 和 xjx_j(1≤lj≤rj≤n1 \leq l_j \leq r_j \leq n,1≤xj≤5⋅1041 \leq x_j \leq 5 \cdot 10^4)。

若 tj=2t_j = 2,则该行后跟两个整数 ljl_j 和 rjr_j(1≤lj≤rj≤n1 \leq l_j \leq r_j \leq n)。

保证至少存在一个类型为 22 的查询。

输出格式

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=4i = 4. So the value is lcm⁡(4,4)gcd⁡(4,4)=44=1\frac{\operatorname{lcm}(4, 4)}{\gcd(4, 4)} = \frac{4}{4} = 1.
  • After the second query the array a=[6,10,15,4,9,25,9,9,9,9]a = [6, 10, 15, 4, 9, 25, 9, 9, 9, 9].
  • For the third query we can choose i=9i = 9. So the value is lcm⁡(9,18)gcd⁡(9,18)=189=2\frac{\operatorname{lcm}(9, 18)}{\gcd(9, 18)} = \frac{18}{9} = 2.

In the second:

  • For the first query we can choose i=4i = 4. So the value is lcm⁡(1,5)gcd⁡(1,5)=51=5\frac{\operatorname{lcm}(1, 5)}{\gcd(1, 5)} = \frac{5}{1} = 5.
  • After the second query the array a=[10,18,18,5]a = [10, 18, 18, 5].
  • After the third query the array a=[10,10,18,5]a = [10, 10, 18, 5].
  • For the fourth query we can choose i=2i = 2. So the value is lcm⁡(10,12)gcd⁡(10,12)=602=30\frac{\operatorname{lcm}(10, 12)}{\gcd(10, 12)} = \frac{60}{2} = 30.

在第一个例子中:

  • 对于第一个查询,我们可以选择 i=4i = 4。因此该值为 lcm⁡(4,4)gcd⁡(4,4)=44=1\frac{\operatorname{lcm}(4, 4)}{\gcd(4, 4)} = \frac{4}{4} = 1。
  • 第二个查询之后,数组 a=[6,10,15,4,9,25,9,9,9,9]a = [6, 10, 15, 4, 9, 25, 9, 9, 9, 9]。
  • 对于第三个查询,我们可以选择 i=9i = 9。因此该值为 lcm⁡(9,18)gcd⁡(9,18)=189=2\frac{\operatorname{lcm}(9, 18)}{\gcd(9, 18)} = \frac{18}{9} = 2。

在第二个例子中:

  • 对于第一个查询,我们可以选择 i=4i = 4。因此该值为 lcm⁡(1,5)gcd⁡(1,5)=51=5\frac{\operatorname{lcm}(1, 5)}{\gcd(1, 5)} = \frac{5}{1} = 5。
  • 第二个查询之后,数组 a=[10,18,18,5]a = [10, 18, 18, 5]。
  • 第三个查询之后,数组 a=[10,10,18,5]a = [10, 10, 18, 5]。
  • 对于第四个查询,我们可以选择 i=2i = 2。因此该值为 lcm⁡(10,12)gcd⁡(10,12)=602=30\frac{\operatorname{lcm}(10, 12)}{\gcd(10, 12)} = \frac{60}{2} = 30。

输入解题思路,AI测评打分。不知道怎么写?

首页