CF471D.MUH and Cube Walls

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of different heights.

Horace was the first to finish making his wall. He called his wall an elephant. The wall consists of w towers. The bears also finished making their wall but they didn't give it a name. Their wall consists of n towers. Horace looked at the bears' tower and wondered: in how many parts of the wall can he "see an elephant"? He can "see an elephant" on a segment of w contiguous towers if the heights of the towers on the segment match as a sequence the heights of the towers in Horace's wall. In order to see as many elephants as possible, Horace can raise and lower his wall. He even can lower the wall below the ground level (see the pictures to the samples for clarification).

Your task is to count the number of segments where Horace can "see an elephant".

圣彼得堡动物园的北极熊门什科夫和乌斯拉达,以及基辅动物园的大象霍拉斯,不知从哪儿弄到了大量木制立方体。他们开始将立方体一个叠一个地堆砌成“立方体塔”。他们将排成一行的多个塔定义为一堵“墙”。一堵墙可由高度各不相同的塔组成。

霍拉斯最先完成了自己的墙,并将其命名为“大象”。这堵墙由 ww 座塔组成。两只熊也完成了他们的墙,但并未给它命名。他们的墙由 nn 座塔组成。霍拉斯看着熊的墙,思考道:在这堵墙中,他能在多少个位置“看到一头大象”?当一段连续的 ww 座塔的高度序列与霍拉斯的“大象”墙中各塔的高度序列完全相同时,霍拉斯便能在该段上“看到一头大象”。为了尽可能多地看到“大象”,霍拉斯可以整体抬升或降低他的墙;他甚至可以将整堵墙降到地面以下(参见样例图片以进一步理解)。

你的任务是计算霍拉斯能“看到大象”的连续段的数量。

输入格式

The first line contains two integers n and w (1 ≤ n, w ≤ 2·105) — the number of towers in the bears' and the elephant's walls correspondingly. The second line contains n integers a__i (1 ≤ a__i ≤ 109) — the heights of the towers in the bears' wall. The third line contains w integers b__i (1 ≤ b__i ≤ 109) — the heights of the towers in the elephant's wall.

第一行包含两个整数 nn 和 ww(1 ≤ n, w ≤ 2⋅1051 ≤ n, w ≤ 2·10^5),分别表示熊的城墙和大象的城墙中的塔的数量。
第二行包含 nn 个整数 aia_i(1 ≤ ai ≤ 1091 ≤ a_i ≤ 10^9),表示熊的城墙中各塔的高度。
第三行包含 ww 个整数 bib_i(1 ≤ bi ≤ 1091 ≤ b_i ≤ 10^9),表示大象的城墙中各塔的高度。

输出格式

Print the number of segments in the bears' wall where Horace can "see an elephant".

输出熊墙中 Horace 能够“看到大象”的线段数量。

输入输出样例

  • 输入#1

    13 5
    2 4 5 5 4 3 2 2 2 3 3 2 1
    3 4 4 3 2

    输出#1

    2

说明/提示

The picture to the left shows Horace's wall from the sample, the picture to the right shows the bears' wall. The segments where Horace can "see an elephant" are in gray.

左侧图片展示了样例中霍勒斯的墙,右侧图片展示了熊们的墙。霍勒斯能够“看到大象”的线段以灰色标出。

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

首页