CF2206E.Parallel Sums
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two integers n and m. For a sequence of n integers A=(a1,a2,…,an), the parallel sums of A are the n−m+1 integers s1,s2,…,sn−m+1 defined by si=ai+ai+1+…+ai+m−1 for each i (1≤i≤n−m+1).
You are given the values of s1,s2,…,sn−m+1. Your task is to answer q queries, described as follows. In the j-th query, you are given two integers lj and rj, and you are asked to find the smallest possible value of max(alj,alj+1,…,arj) among all sequences A=(a1,a2,…,an) of n integers (possibly negative) such that s1,s2,…,sn−m+1 are the parallel sums of A. Or determine if this value can be arbitrarily small.
给你两个整数 n 和 m。对于一个长度为 n 的整数序列 A=(a1,a2,…,an),其并行和(parallel sums)定义为 n−m+1 个整数 s1,s2,…,sn−m+1,其中对每个 i(1≤i≤n−m+1),有
si=ai+ai+1+…+ai+m−1.
你已知 s1,s2,…,sn−m+1 的值。你的任务是回答 q 个查询,具体如下:在第 j 个查询中,你将获得两个整数 lj 和 rj,要求找出所有满足条件的整数序列 A=(a1,a2,…,an)(元素可为负数)中,max(alj,alj+1,…,arj) 的最小可能值;这里的“满足条件”指 s1,s2,…,sn−m+1 恰好是 A 的并行和。若该最小值可以任意小(即无下界),则需判定这一点。
输入格式
The first line of input contains two integers n and m (1≤m≤n≤200000).
The second line contains n−m+1 integers s1,s2,…,sn−m+1 (−109≤si≤109).
The third line contains a single integer q (1≤q≤100000).
The j-th of the next q lines contains two integers lj and rj (1≤lj≤rj≤n).
输入的第一行包含两个整数 n 和 m(1≤m≤n≤200000)。
第二行包含 n−m+1 个整数 s1,s2,…,sn−m+1(−109≤si≤109)。
第三行包含一个整数 q(1≤q≤100000)。
接下来的 q 行中,第 j 行包含两个整数 lj 和 rj(1≤lj≤rj≤n)。
输出格式
Output q lines. The j-th line should contain the smallest possible value of max(alj,alj+1,…,arj). If that value can be arbitrarily small, output unbounded instead.
输出 q 行。第 j 行应包含 max(alj,alj+1,…,arj) 的最小可能值。若该值可以任意小,则输出 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). The parallel sums of A are (4,−4,2,6,5) as required. Then max(a3,…,a7)=max(−3,2,1,2,1)=2. It can be shown that 2 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). Then 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 的并行和为 (4,−4,2,6,5),符合要求。此时 max(a3,…,a7)=max(−3,2,1,2,1)=2。可以证明 2 是可能的最小值。
对于第二个查询,该值可任意小。
对于第三个查询,取 A=(4,−3,0,3,−4,3,4,2)。此时 max(4,−3,0,3,−4,3,4,2)=4,这是可能的最小值。
输入解题思路,AI测评打分。不知道怎么写?