CF232D.Fence
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
John Doe has a crooked fence, consisting of n rectangular planks, lined up from the left to the right: the plank that goes i-th (1 ≤ i ≤ n) (from left to right) has width 1 and height h__i. We will assume that the plank that goes i-th (1 ≤ i ≤ n) (from left to right) has index i.
A piece of the fence from l to r (1 ≤ l ≤ r ≤ n) is a sequence of planks of wood with indices from l to r inclusive, that is, planks with indices l, l + 1, ..., r. The width of the piece of the fence from l to r is value r - l + 1.
Two pieces of the fence from _l_1 to _r_1 and from _l_2 to _r_2 are called matching, if the following conditions hold:
- the pieces do not intersect, that is, there isn't a single plank, such that it occurs in both pieces of the fence;
- the pieces are of the same width;
- for all i (0 ≤ i ≤ _r_1 - _l_1) the following condition holds: _h__l_1 + i + _h__l_2 + i = _h__l_1 + _h__l_2.
John chose a few pieces of the fence and now wants to know how many distinct matching pieces are for each of them. Two pieces of the fence are distinct if there is a plank, which belongs to one of them and does not belong to the other one.
约翰·多伊尔有一道歪斜的栅栏,由 n 个矩形木板从左到右依次排列组成:第 i 块木板(1≤i≤n,从左往右数)宽度为 1,高度为 hi。我们将第 i 块木板(1≤i≤n,从左往右数)称为索引为 i 的木板。
栅栏中从 l 到 r(1≤l≤r≤n)的一段,是指索引从 l 到 r(含端点)的所有木板构成的序列,即索引为 l,l+1,…,r 的木板。该段栅栏的宽度为 r−l+1。
两段栅栏——一段为从 l1 到 r1,另一段为从 l2 到 r2——被称为匹配的,当且仅当满足以下条件:
- 这两段互不相交,即不存在任何一块木板同时属于这两段栅栏;
- 这两段具有相同的宽度;
- 对所有 i(0≤i≤r1−l1),均满足:
hl1+i+hl2+i=hl1+hl2.
约翰选取了栅栏中的若干段,现在他想知道:对其中每一段,有多少段互不相同的匹配段。若存在某块木板属于其中一段但不属于另一段,则称这两段栅栏是不同的。
输入格式
The first line contains integer n (1 ≤ n ≤ 105) — the number of wood planks in the fence. The second line contains n space-separated integers _h_1, _h_2, ..., h__n (1 ≤ h__i ≤ 109) — the heights of fence planks.
The third line contains integer q (1 ≤ q ≤ 105) — the number of queries. Next q lines contain two space-separated integers l__i and r__i (1 ≤ l__i ≤ r__i ≤ n) — the boundaries of the i-th piece of the fence.
第一行包含一个整数 n(1≤n≤105)——围栏中木板的数量。
第二行包含 n 个用空格分隔的整数 h1,h2,…,hn(1≤hi≤109)——围栏木板的高度。
第三行包含一个整数 q(1≤q≤105)——查询的数量。
接下来的 q 行每行包含两个用空格分隔的整数 li 和 ri(1≤li≤ri≤n)——第 i 段围栏的边界。
输出格式
For each query on a single line print a single integer — the number of pieces of the fence that match the given one. Print the answers to the queries in the order, in which the queries are given in the input.
对于每个查询,在一行中输出一个整数——与给定栅栏段匹配的栅栏段数量。按照输入中查询给出的顺序输出各查询的答案。
输入输出样例
输入#1
10 1 2 2 1 100 99 99 100 100 100 6 1 4 1 2 3 4 1 5 9 10 10 10
输出#1
1 2 2 0 2 9
输入解题思路,AI测评打分。不知道怎么写?