AT_abc481_b.Polyline

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are NN points on the xyxy-plane, numbered 1,2,…,N1,2,\ldots,N. The coordinates of point ii are (i,Ai)(i,A_i).

For i=1,2,…,N−1i=1,2,\ldots,N-1, connect point ii and point i+1i+1 with a line segment to form one polyline.

Find the number of points on this polyline (including its endpoints) whose yy-coordinate is KK.

Here, the constraints guarantee that the number of points satisfying the condition is finite.

在 xyxy-平面上有 NN 个点,编号为 1,2,…,N1,2,\ldots,N。点 ii 的坐标为 (i,Ai)(i,A_i)。

对 i=1,2,…,N−1i=1,2,\ldots,N-1,用线段连接点 ii 和点 i+1i+1,从而构成一条折线。

求这条折线上(包括端点)纵坐标(即 yy-坐标)恰好为 KK 的点的个数。

此处,题目约束条件保证满足该条件的点的个数是有限的。

输入格式

The input is given from Standard Input in the following format:

NN KK
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入中按以下格式给出:

NN KK
A1A_1 A2A_2 …\ldots ANA_N

输出格式

Print the number of points on the polyline whose yy-coordinate is KK.

输出折线上 yy 坐标为 KK 的点的个数。

输入输出样例

  • 输入#1

    5 3
    1 3 1 5 1

    输出#1

    3
  • 输入#2

    3 3
    3 1 3

    输出#2

    2
  • 输入#3

    2 100
    1 2

    输出#3

    0

说明/提示

Sample 1 Explanation:
As shown in the figure below, there are 33 points satisfying the condition: (2,3)(2,3), (72,3)(\frac{7}{2},3), and (92,3)(\frac{9}{2},3).

Note that the point (2,3)(2,3) is a common endpoint of the segment connecting points 11 and 22 and the segment connecting points 22 and 33, but it is counted as one point.

Sample 2 Explanation:
There are 22 points satisfying the condition: (1,3)(1,3) and (3,3)(3,3). Note that the points at the ends of the polyline are also counted.

Constraints

  • 2≤N≤1002 \le N \le 100
  • 1≤Ai≤1001 \le A_i \le 100 (1≤i≤N)(1 \le i \le N)
  • Ai≠Ai+1A_i \ne A_{i+1} (1≤i<N)(1 \le i < N)
  • 1≤K≤1001 \le K \le 100
  • All input values are integers.

样例 1 解释:
如下方图示所示,共有 33 个满足条件的点:(2,3)(2,3)、(72,3)(\frac{7}{2},3) 和 (92,3)(\frac{9}{2},3)。

注意:点 (2,3)(2,3) 同时是连接第 11 个点与第 22 个点的线段、以及连接第 22 个点与第 33 个点的线段的公共端点,但仍只计为一个点。

样例 2 解释:
共有 22 个满足条件的点:(1,3)(1,3) 和 (3,3)(3,3)。注意:折线两端的点也计入总数。

约束条件

  • 2≤N≤1002 \le N \le 100
  • 1≤Ai≤1001 \le A_i \le 100(1≤i≤N1 \le i \le N)
  • Ai≠Ai+1A_i \ne A_{i+1}(1≤i<N1 \le i < N)
  • 1≤K≤1001 \le K \le 100
  • 所有输入值均为整数。

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

首页