F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

F. Product of Sorting Powers

Time Limit: 23000/11500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 645    Accepted Submission(s): 42


Problem Description
Given a sequence $A$ of length $n$.

There are $m$ queries, each given $l, r$, let $B_1, B_2, \dots, B_{r - l + 1}$ as the result of sorting $A_l, A_{l + 1}, \dots, A_r$, calculate:

$$\left(\prod_{i = 1} ^ {r - l} {B_i} ^ {B_{i + 1}} \right) \bmod {(10 ^ 9 + 7)}$$
 

Input
The first line of the input contains two integers $n, m$ ($1 \le n \le 10 ^ 6$, $1 \le m \le 5000$) - the length of $A$ and the number of queries.

The second line contains $n$ integers $A_1, A_2, \dots, A_n$ ($1 \le A_i \le 10^9$).

Each of the following $m$ lines contains two integers $l, r$ ($1 \le l \le r \le n$).
 

Output
For each query, print a single integer - the answer of the query, modulo $10 ^ 9 + 7$.
 

Sample Input
6 5 8 2 5 9 7 7 1 4 2 6 1 3 3 6 2 5
 

Sample Output
588255953 426219106 12500000 575819351 16793812
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 05:21:18, Gzip enabled