#P9285. [AGM 2023 资格赛] YsaeSort

[AGM 2023 资格赛] YsaeSort

Problem Description

Given a sequence AA of length NN, you will perform QQ operations:

  • 1 l r (1lrN)1\ l\ r\ (1 \leq l \leq r \leq N) means sorting the interval [l,r][l, r].

  • 2 l r (1lrN)2\ l\ r\ (1 \leq l \leq r \leq N) is a query: if you perform bubble sort on this interval, what is the maximum product of the two adjacent numbers that get swapped.

It is guaranteed that the intervals sorted by operation 11 are pairwise disjoint or one contains another.

Input Format

The first line contains an integer N (1N5×104)N\ (1 \leq N \leq 5 \times 10^4), the number of elements in the array.

The second line contains NN integers (0A[i]109, 1iN)(0 \leq A[i] \leq 10^9,\ 1 \leq i \leq N), the elements of the array.

The third line contains an integer Q (1Q5×104)Q\ (1 \leq Q \leq 5 \times 10^4), the number of operations.

Each of the next QQ lines contains one query described above.

Output Format

Output QQ lines. For each query, output the answer.

10
10 9 8 7 6 5 4 3 2 1
11
1 1 2
2 1 2
2 1 3
2 1 10
2 9 10
1 3 4
2 1 4
2 3 4
2 2 3
1 1 4
2 1 4

0
80
80
2
80
0
70
0

Hint

Translated by ChatGPT 5