CF1485B.Replace and Keep Sorted

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given a positive integer kk, two arrays are called kk-similar if:

  • they are strictly increasing;
  • they have the same length;
  • all their elements are positive integers between 11 and kk (inclusive);
  • they differ in exactly one position.

You are given an integer kk, a strictly increasing array aa and qq queries. For each query, you are given two integers li≤ril_i \leq r_i. Your task is to find how many arrays bb exist, such that bb is kk-similar to array [ali,ali+1…,ari][a_{l_i},a_{l_i+1}\ldots,a_{r_i}].

给定一个正整数 kk,若两个数组满足以下条件,则称它们是 kk-相似的:

  • 它们均为严格递增数组;
  • 它们的长度相同;
  • 所有元素均为介于 11 到 kk(含端点)之间的正整数;
  • 它们在恰好一个位置上的元素不同。

现给出一个整数 kk、一个严格递增数组 aa 以及 qq 个查询。对每个查询,给定两个整数 li≤ril_i \leq r_i。你的任务是:求出满足条件的数组 bb 的个数,使得 bb 与子数组 [ali,ali+1,…,ari][a_{l_i},a_{l_i+1},\ldots,a_{r_i}] 是 kk-相似的。

输入格式

The first line contains three integers nn, qq and kk (1≤n,q≤1051\leq n, q \leq 10^5, n≤k≤109n\leq k \leq 10^9) — the length of array aa, the number of queries and number kk.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots,a_n (1≤ai≤k1 \leq a_i \leq k). This array is strictly increasing — a1<a2<…<ana_1 \lt a_2 \lt \ldots \lt a_n.

Each of the following qq lines contains two integers lil_i, rir_i (1≤li≤ri≤n1 \leq l_i \leq r_i \leq n).

第一行包含三个整数 nn、qq 和 kk(1≤n,q≤1051\leq n, q \leq 10^5,n≤k≤109n\leq k \leq 10^9)—— 分别表示数组 aa 的长度、查询次数以及数字 kk。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots,a_n(1≤ai≤k1 \leq a_i \leq k)。该数组严格递增——即满足 a1<a2<…<ana_1 \lt a_2 \lt \ldots \lt a_n。

接下来的 qq 行中,每行包含两个整数 lil_i、rir_i(1≤li≤ri≤n1 \leq l_i \leq r_i \leq n)。

输出格式

Print qq lines. The ii-th of them should contain the answer to the ii-th query.

输出 qq 行。其中第 ii 行应包含第 ii 个查询的答案。

输入输出样例

  • 输入#1

    4 2 5
    1 2 4 5
    2 3
    3 4

    输出#1

    4
    3
  • 输入#2

    6 5 10
    2 4 6 7 8 9
    1 4
    1 2
    3 5
    1 6
    5 5

    输出#2

    8
    9
    7
    6
    9

说明/提示

In the first example:

In the first query there are 44 arrays that are 55-similar to [2,4][2,4]: [1,4],[3,4],[2,3],[2,5][1,4],[3,4],[2,3],[2,5].

In the second query there are 33 arrays that are 55-similar to [4,5][4,5]: [1,5],[2,5],[3,5][1,5],[2,5],[3,5].

在第一个示例中:

第一个查询中,有 44 个数组与 [2,4][2,4] 是 55-相似的:[1,4],[3,4],[2,3],[2,5][1,4],[3,4],[2,3],[2,5]。

第二个查询中,有 33 个数组与 [4,5][4,5] 是 55-相似的:[1,5],[2,5],[3,5][1,5],[2,5],[3,5]。

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

首页