PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000389. Vị trí tối ưu (Location)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Vị trí tối ưu (Location)

Location

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given two arrays a1,…,ana_1,\ldots,a_n and b1,…,bnb_1,\ldots,b_n of positive integers. Array bb is fixed, while array aa can be modified.

Process qq operations in order:

  • 1 l r x: assign ai=xa_i=x for every l≤i≤rl\le i\le r.
  • 2 l r: output the minimum over l≤i≤rl\le i\le r of
$$\frac{\operatorname{lcm}(a_i,b_i)}{\gcd(a_i,b_i)}.$$

Both GCD and LCM are taken on positive integers, so the expression is a positive integer.

Input

  • First line: n,qn,q.
  • Second line: nn integers aia_i.
  • Third line: nn integers bib_i.
  • Next qq lines: operations of type 1 l r x or 2 l r.

At least one type-2 query is guaranteed.

Output

For every type-2 query print the required minimum on its own line.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤301\le n,q\le30; 1≤ai,bi,x≤501\le a_i,b_i,x\le50; 1≤l≤r≤n1\le l\le r\le n.

  • Subtask 2 (30 points): 1≤n,q≤1 0001\le n,q\le1\,000; 1≤ai,bi,x≤2 0001\le a_i,b_i,x\le2\,000; 1≤l≤r≤n1\le l\le r\le n.

  • Subtask 3 (50 points): 1≤n,q≤50 0001\le n,q\le50\,000; 1≤ai,bi,x≤50 0001\le a_i,b_i,x\le50\,000; 1≤l≤r≤n1\le l\le r\le n.

Examples

Example 1

Input

4 4
10 2 12 5
1 12 16 1
2 2 4
1 2 3 18
1 2 2 10
2 2 3

Output

5
30

Explanation

Initially positions 2,3,42,3,4 have ratios 6,12,56,12,5; the minimum is 55. After both assignments, position 22 has ratio lcm⁡(10,12)/gcd⁡(10,12)=30\operatorname{lcm}(10,12)/\gcd(10,12)=30 while position 33 has ratio lcm⁡(18,16)/gcd⁡(18,16)=72\operatorname{lcm}(18,16)/\gcd(18,16)=72, so the second answer is 3030.

Example 2

Input

3 4
4 6 9
6 6 3
2 1 3
1 1 3 6
2 1 3
2 3 3

Output

1
1
2

Explanation

The first range contains two equal values at position 22, so its minimum is 11. Assigning ai=6a_i=6 for all positions makes the second minimum 11. Finally, the ratio at position 33 is 6/3=26/3=2.