CF1119D.Frets On Fire

普及+/提高

通过率:0%

时间限制:1.50s

内存限制:256MB

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 nn strings, and each string has (1018+1)(10^{18} + 1) frets numerated from 00 to 101810^{18}. The fleas use the array s1,s2,…,sns_1, s_2, \ldots, s_n to describe the ukulele's tuning, that is, the pitch of the jj-th fret on the ii-th string is the integer si+js_i + 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 ll and rr (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 nn rows and (1018+1)(10^{18}+1) columns, where the cell in the ii-th row and jj-th column (0≤j≤10180 \le j \le 10^{18}) contains the integer si+js_i + j. You are to answer qq queries, in the kk-th query you have to answer the number of distinct integers in the matrix from the lkl_k-th to the rkr_k-th columns, inclusive.

宫野带着一把尤克里里来到跳蚤王国。她与当地的跳蚤居民成为好朋友,并且每天为他们演奏优美的音乐。

作为回报,跳蚤们为她制作了一把更大的尤克里里:它有 nn 根弦,每根弦上有 (1018+1)(10^{18} + 1) 个品,编号从 00 到 101810^{18}。跳蚤们用数组 s1,s2,…,sns_1, s_2, \ldots, s_n 来描述这把尤克里里的调音方式,即第 ii 根弦上第 jj 个品所发出的音高为整数 si+js_i + j。

宫野即将离开跳蚤王国,但跳蚤们希望她在临行前回答一些最后的问题。

每个问题的形式为:“若考虑所有弦上编号在 ll 到 rr(含端点)之间的品,共有多少种不同的音高?”

宫野即将前往蟋蟀王国,没有时间逐一回答所有问题。请帮她完成这项任务!

形式化地,你被给定一个 nn 行、(1018+1)(10^{18}+1) 列的矩阵,其中第 ii 行第 jj 列(0≤j≤10180 \le j \le 10^{18})的元素为整数 si+js_i + j。你需要回答 qq 个查询;在第 kk 个查询中,你需要计算该矩阵中从第 lkl_k 列到第 rkr_k 列(含端点)的所有元素中不同整数的个数。

输入格式

The first line contains an integer nn (1≤n≤100 0001 \leq n \leq 100\,000) — the number of strings.

The second line contains nn integers s1,s2,…,sns_1, s_2, \ldots, s_n (0≤si≤10180 \leq s_i \leq 10^{18}) — the tuning of the ukulele.

The third line contains an integer qq (1≤q≤100 0001 \leq q \leq 100\,000) — the number of questions.

The kk-th among the following qq lines contains two integers lkl_k,rkr_k (0≤lk≤rk≤10180 \leq l_k \leq r_k \leq 10^{18}) — a question from the fleas.

第一行包含一个整数 nn(1≤n≤100 0001 \leq n \leq 100\,000)—— 字符串的数量。

第二行包含 nn 个整数 s1,s2,…,sns_1, s_2, \ldots, s_n(0≤si≤10180 \leq s_i \leq 10^{18})—— 尤克里里的调音值。

第三行包含一个整数 qq(1≤q≤100 0001 \leq q \leq 100\,000)—— 问题的数量。

接下来的 qq 行中,第 kk 行包含两个整数 lkl_k、rkr_k(0≤lk≤rk≤10180 \leq l_k \leq r_k \leq 10^{18})—— 跳蚤提出的一个问题。

输出格式

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.

\\begin{matrix} \\textbf{Fret} & \\textbf{0} & \\textbf{1} & \\textbf{2} & \\textbf{3} & \\textbf{4} & \\textbf{5} & \\textbf{6} & \\textbf{7} & \\ldots \\\\ s\_1: & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & \\dots \\\\ s\_2: & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \\dots \\\\ s\_3: & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & \\dots \\\\ s\_4: & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \\dots \\\\ s\_5: & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & \\dots \\\\ s\_6: & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & \\dots \\end{matrix}

There are 55 different pitches on fret 77 — 8,10,11,12,168, 10, 11, 12, 16.

There are 1010 different pitches on frets 0,1,20, 1, 2 — 1,2,3,4,5,6,7,9,10,111, 2, 3, 4, 5, 6, 7, 9, 10, 11.

对于第一个例子,6根弦在各品上的音高如下:

品01234567…s_1:345678910…s_2:12345678…s_3:4567891011…s_4:12345678…s_5:56789101112…s_6:910111213141516…\begin{matrix} \textbf{品} & \textbf{0} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} & \textbf{6} & \textbf{7} & \ldots \\ s\_1: & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & \dots \\ s\_2: & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \dots \\ s\_3: & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & \dots \\ s\_4: & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \dots \\ s\_5: & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & \dots \\ s\_6: & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & \dots \end{matrix}

在第7品上有5个不同的音高:8,10,11,12,168, 10, 11, 12, 16。

在第0、1、2品上共有10个不同的音高:1,2,3,4,5,6,7,9,10,111, 2, 3, 4, 5, 6, 7, 9, 10, 11。

输入解题思路,AI测评打分。不知道怎么写?

首页