CF2206E.Parallel Sums

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given two integers nn and mm. For a sequence of nn integers A=(a1,a2,…,an)A=(a_1, a_2, \ldots, a_n), the parallel sums of AA are the n−m+1n-m+1 integers s1,s2,…,sn−m+1s_1, s_2, \ldots, s_{n-m+1} defined by si=ai+ai+1+…+ai+m−1s_i = a_i + a_{i+1} + \ldots + a_{i+m-1} for each ii (1≤i≤n−m+11 \leq i \leq n-m+1).

You are given the values of s1,s2,…,sn−m+1s_1, s_2, \ldots, s_{n-m+1}. Your task is to answer qq queries, described as follows. In the jj-th query, you are given two integers ljl_j and rjr_j, and you are asked to find the smallest possible value of max⁡(alj,alj+1,…,arj)\max(a_{l_j}, a_{l_j+1}, \ldots, a_{r_j}) among all sequences A=(a1,a2,…,an)A=(a_1, a_2, \ldots, a_n) of nn integers (possibly negative) such that s1,s2,…,sn−m+1s_1, s_2, \ldots, s_{n-m+1} are the parallel sums of AA. Or determine if this value can be arbitrarily small.

给你两个整数 nn 和 mm。对于一个长度为 nn 的整数序列 A=(a1,a2,…,an)A=(a_1, a_2, \ldots, a_n),其并行和(parallel sums)定义为 n−m+1n-m+1 个整数 s1,s2,…,sn−m+1s_1, s_2, \ldots, s_{n-m+1},其中对每个 ii(1≤i≤n−m+11 \leq i \leq n-m+1),有

si=ai+ai+1+…+ai+m−1.s_i = a_i + a_{i+1} + \ldots + a_{i+m-1}.

你已知 s1,s2,…,sn−m+1s_1, s_2, \ldots, s_{n-m+1} 的值。你的任务是回答 qq 个查询,具体如下:在第 jj 个查询中,你将获得两个整数 ljl_j 和 rjr_j,要求找出所有满足条件的整数序列 A=(a1,a2,…,an)A=(a_1, a_2, \ldots, a_n)(元素可为负数)中,max⁡(alj,alj+1,…,arj)\max(a_{l_j}, a_{l_j+1}, \ldots, a_{r_j}) 的最小可能值;这里的“满足条件”指 s1,s2,…,sn−m+1s_1, s_2, \ldots, s_{n-m+1} 恰好是 AA 的并行和。若该最小值可以任意小(即无下界),则需判定这一点。

输入格式

The first line of input contains two integers nn and mm (1≤m≤n≤200 0001 \leq m \leq n \leq 200\,000).

The second line contains n−m+1n-m+1 integers s1,s2,…,sn−m+1s_1, s_2, \ldots, s_{n-m+1} (−109≤si≤109-10^9 \leq s_i \leq 10^9).

The third line contains a single integer qq (1≤q≤100 0001 \leq q \leq 100\,000).

The jj-th of the next qq lines contains two integers ljl_j and rjr_j (1≤lj≤rj≤n1 \leq l_j \leq r_j \leq n).

输入的第一行包含两个整数 nn 和 mm(1≤m≤n≤200 0001 \leq m \leq n \leq 200\,000)。

第二行包含 n−m+1n-m+1 个整数 s1,s2,…,sn−m+1s_1, s_2, \ldots, s_{n-m+1}(−109≤si≤109-10^9 \leq s_i \leq 10^9)。

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

接下来的 qq 行中,第 jj 行包含两个整数 ljl_j 和 rjr_j(1≤lj≤rj≤n1 \leq l_j \leq r_j \leq n)。

输出格式

Output qq lines. The jj-th line should contain the smallest possible value of max⁡(alj,alj+1,…,arj)\max(a_{l_j}, a_{l_j+1}, \ldots, a_{r_j}). If that value can be arbitrarily small, output unbounded instead.

输出 qq 行。第 jj 行应包含 max⁡(alj,alj+1,…,arj)\max(a_{l_j}, a_{l_j+1}, \ldots, a_{r_j}) 的最小可能值。若该值可以任意小,则输出 unbounded。

输入输出样例

  • 输入#1

    8 4
    4 -4 2 6 5
    4
    3 7
    4 6
    1 8
    2 5

    输出#1

    2
    unbounded
    4
    -1

说明/提示

Explanation for the sample input/output #1

For the first query, take A=(9,−4,−3,2,1,2,1,1)A = (9, -4, -3, 2, 1, 2, 1, 1). The parallel sums of AA are (4,−4,2,6,5)(4, -4, 2, 6, 5) as required. Then max⁡(a3,…,a7)=max⁡(−3,2,1,2,1)=2\max(a_3, \ldots, a_7) = \max(-3, 2, 1, 2, 1) = 2. It can be shown that 22 is the smallest possible value.

For the second query, you can make the value arbitrarily small.

For the third query, take A=(4,−3,0,3,−4,3,4,2)A = (4, -3, 0, 3, -4, 3, 4, 2). Then max⁡(4,−3,0,3,−4,3,4,2)=4\max(4, -3, 0, 3, -4, 3, 4, 2) = 4, which is the smallest possible value.

样例输入/输出 #1 的解释

对于第一个查询,取 A=(9,−4,−3,2,1,2,1,1)A = (9, -4, -3, 2, 1, 2, 1, 1)。AA 的并行和为 (4,−4,2,6,5)(4, -4, 2, 6, 5),符合要求。此时 max⁡(a3,…,a7)=max⁡(−3,2,1,2,1)=2\max(a_3, \ldots, a_7) = \max(-3, 2, 1, 2, 1) = 2。可以证明 22 是可能的最小值。

对于第二个查询,该值可任意小。

对于第三个查询,取 A=(4,−3,0,3,−4,3,4,2)A = (4, -3, 0, 3, -4, 3, 4, 2)。此时 max⁡(4,−3,0,3,−4,3,4,2)=4\max(4, -3, 0, 3, -4, 3, 4, 2) = 4,这是可能的最小值。

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

首页