AT_abc468_f.Chmax

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a positive integer NN and a permutation P=(P1,P2,…,PN)P=(P_1,P_2,\ldots,P_N) of (1,2,…,N)(1,2,\ldots,N).

There are variables x,y,cx,y,c. Initially, x=y=c=0x=y=c=0.

For k=1,2,…,Nk=1,2,\ldots,N in this order, you perform one of the following operations:

  • Operation 11: Increase cc by 11 if x<Pkx < P_k. Then, replace xx with max⁡(x,Pk)\max(x,P_k).
  • Operation 22: Increase cc by 11 if y<Pky < P_k. Then, replace yy with max⁡(y,Pk)\max(y,P_k).

Find the maximum possible final value of cc.

给定一个正整数 NN 和 (1,2,…,N)(1,2,\ldots,N) 的一个排列 P=(P1,P2,…,PN)P=(P_1,P_2,\ldots,P_N)。

有三个变量 x,y,cx, y, c,初始时 x=y=c=0x = y = c = 0。

按 k=1,2,…,Nk = 1, 2, \ldots, N 的顺序,对每个 kk 执行以下两种操作之一:

  • 操作 11:若 x<Pkx < P_k,则将 cc 增加 11;然后将 xx 替换为 max⁡(x,Pk)\max(x, P_k)。
  • 操作 22:若 y<Pky < P_k,则将 cc 增加 11;然后将 yy 替换为 max⁡(y,Pk)\max(y, P_k)。

求 cc 的最终值所能达到的最大可能值。

输入格式

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

NN
P1P_1 P2P_2 …\ldots PNP_N

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

NN
P1P_1 P2P_2 …\ldots PNP_N

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    5
    4 3 1 2 5

    输出#1

    4
  • 输入#2

    6
    6 5 4 3 2 1

    输出#2

    2
  • 输入#3

    9
    3 6 5 2 7 8 9 1 4

    输出#3

    7

说明/提示

Sample 1 Explanation:
By performing the operations as follows, you can achieve c=4c=4:

  • For k=1k=1: Perform operation 11. Then, (x,y,c)=(4,0,1)(x,y,c)=(4,0,1).
  • For k=2k=2: Perform operation 11. Then, (x,y,c)=(4,0,1)(x,y,c)=(4,0,1).
  • For k=3k=3: Perform operation 22. Then, (x,y,c)=(4,1,2)(x,y,c)=(4,1,2).
  • For k=4k=4: Perform operation 22. Then, (x,y,c)=(4,2,3)(x,y,c)=(4,2,3).
  • For k=5k=5: Perform operation 22. Then, (x,y,c)=(4,5,4)(x,y,c)=(4,5,4).

cc cannot be made greater than 44 no matter how you perform the operations, so output 44.

Constraints

  • 1≤N≤5×1051\le N\le 5\times 10^5
  • PP is a permutation of (1,2,…,N)(1,2,\ldots,N).
  • All input values are integers.

样例 1 解释:
通过执行如下操作,可使 c=4c=4:

  • 当 k=1k=1 时:执行操作 1。此时 (x,y,c)=(4,0,1)(x,y,c)=(4,0,1)。
  • 当 k=2k=2 时:执行操作 1。此时 (x,y,c)=(4,0,1)(x,y,c)=(4,0,1)。
  • 当 k=3k=3 时:执行操作 2。此时 (x,y,c)=(4,1,2)(x,y,c)=(4,1,2)。
  • 当 k=4k=4 时:执行操作 2。此时 (x,y,c)=(4,2,3)(x,y,c)=(4,2,3)。
  • 当 k=5k=5 时:执行操作 2。此时 (x,y,c)=(4,5,4)(x,y,c)=(4,5,4)。

无论以何种方式执行操作,cc 均无法超过 44,因此输出 44。

限制条件

  • 1≤N≤5×1051\le N\le 5\times 10^5
  • PP 是 (1,2,…,N)(1,2,\ldots,N) 的一个排列。
  • 所有输入值均为整数。

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

首页