CF1119D.Frets On Fire
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Miyako came to the flea kingdom with a ukulele. She became good friends with local flea residents and played beautiful music for them every day.
In return, the fleas made a bigger ukulele for her: it has n strings, and each string has (1018+1) frets numerated from 0 to 1018 . The fleas use the array s1,s2,…,sn to describe the ukulele's tuning, that is, the pitch of the j -th fret on the i -th string is the integer si+j .
Miyako is about to leave the kingdom, but the fleas hope that Miyako will answer some last questions for them.
Each question is in the form of: "How many different pitches are there, if we consider frets between l and r (inclusive) on all strings?"
Miyako is about to visit the cricket kingdom and has no time to answer all the questions. Please help her with this task!
Formally, you are given a matrix with n rows and (1018+1) columns, where the cell in the i -th row and j -th column ( 0≤j≤1018 ) contains the integer si+j . You are to answer q queries, in the k -th query you have to answer the number of distinct integers in the matrix from the lk -th to the rk -th columns, inclusive.
输入格式
The first line contains an integer n ( 1≤n≤100000 ) — the number of strings.
The second line contains n integers s1,s2,…,sn ( 0≤si≤1018 ) — the tuning of the ukulele.
The third line contains an integer q ( 1≤q≤100000 ) — the number of questions.
The k -th among the following q lines contains two integers lk , rk ( 0≤lk≤rk≤1018 ) — a question from the fleas.
输出格式
Output one number for each question, separated by spaces — the number of different pitches.
输入输出样例
输入#1
6 3 1 4 1 5 9 3 7 7 0 2 8 17
输出#1
5 10 18
输入#2
2 1 500000000000000000 2 1000000000000000000 1000000000000000000 0 1000000000000000000
输出#2
2 1500000000000000000
说明/提示
For the first example, the pitches on the 66 strings are as follows.
Frets1:s2:s3:s4:s5:s6:031415914252610253637113647481247585913586961014697107111571081181216…………………
There are 5 different pitches on fret 7 — 8,10,11,12,16
There are 10 different pitches on frets 0,1,2 — 1,2,3,4,5,6,7,9,10,11