Time limit: 1 second Memory limit: 64 MB function f ( i , J ) f(i,j) on the array a a to…
- User
Time limit: 1 second Memory limit: 64 MB function f ( i , J ) f(i,j) on the array a a to length n n is defined as follows:
f ( i , i )
a i f(i,i)=a i
f ( i , J )
m a x ( f ( i + 1 , J ) , f ( i , J
1 ) , m i n ( a i , a i + 1 , . . . , a J ) x ( J
i + 1 ) ) ( i < J ) f(i,j)=max(f(i+1,j),f(i,j−1),min(a i , a i+1 ,...,a J )×(j−i+1))(i<j) to you Q Q is a given pair of numbers.
Each pair has two numbers l i l i and r i r i is
Output the following value:
m a x ( f ( l 1 , r 1 ) , f ( l 2 , r 2 ) , . . . , f ( l Q , r Q ) ) max(f(l 1 R 1 ),f(l 2 R 2 ),...,f(l Q R Q ))
input In the first line, two numbers n n and Q Q is given.
In the next line n n number a 1 a 1 until a n a n is given
in Q Q next line l i l i and r i r i It will be given to you.
1 ≤ Q , n ≤ 1
000
000 1≤Q,n≤1 000 000
1 ≤ a i ≤ 1
000
000
000 1≤a i ≤1 000 000 000
1 ≤ l i ≤ r i ≤ n 1≤l i ≤r i ≤n
All numbers in the array are guaranteed a a are distinct.
output Output the requested value.
Example Sample input 1 5 2 1 4 3 5 2 1 3 3 5
Plain text Sample output 1 6 write code in java17
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.