日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Eming cup Problem D. Game of numbers

發布時間:2024/4/17 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eming cup Problem D. Game of numbers 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Time Limit:?0.5 seconds

Memory Limit:?512 mebibytes

Mingming loves playing with numbers, and today, someone gives him a permutation of?nn?:?P_1, P_2\ldots P_nP?1??,P?2??P?n??.

Nannan is Mingming's friend, then he asked Mingming: if he select a number?xx?between?[l, r][l,r], and them select another number?yy?in range?(x, r](x,r], then calculate?A_xA_yA?x??A?y??. It is clear that there are many valid selections. Nannan wants to know the sum of them. As the number can be very large, you only have to output the answer module?10^9 + 710?9??+7

To make Mingming enjoy the game more, Nannan gives him?QQ?pairs of?l, rl,r. Of course, Mingming can solve this problem. But now, he wants to check if you can solve the problem.

More exactly, your task is to calculate?\sum_{l\le i\le r}\sum_{i< j\le r} A_iA_j?lir???i<jr??A?i??A?j???module?10^9 + 710?9??+7?for each?l, rl,r, where?A_1, A_2, \ldots A_nA?1??,A?2??,A?n???is a permutation of?nn.

Input

First line is a number?nn(3\le n\le 10^53n10?5??), which means the length of sequence a.

Second line is?nn?numbers from?A_1A?1???to?A_nA?n??(1\le A_i\le 10^51A?i??10?5??, for each?i \neq jij,?A_i \neq A_jA?i??A?j??).

Third line is a number?Q(1\le Q\le 10^5)Q(1Q10?5??)?means how many pairs of?ll?and?rr?will be chosen.

In the next?QQ?lines, the?ii-th one contians two integers?ll?and?rr?(l< rl<r), which is the?ii-th query.

Output

Output?QQ?lines of answers for each pairs query.

Examples

Sample Input

5 3 2 4 1 5 2 1 2 2 4

Sample Output

6 14

Note

2?times×?500000004?\equiv≡?1 (mod?10^9+710?9??+7)

前綴和

?

轉載于:https://www.cnblogs.com/sakumia/p/6507119.html

總結

以上是生活随笔為你收集整理的Eming cup Problem D. Game of numbers的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。