AT_abc468_f.Chmax
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer N and a permutation P=(P1,P2,…,PN) of (1,2,…,N).
There are variables x,y,c. Initially, x=y=c=0.
For k=1,2,…,N in this order, you perform one of the following operations:
- Operation 1: Increase c by 1 if x<Pk. Then, replace x with max(x,Pk).
- Operation 2: Increase c by 1 if y<Pk. Then, replace y with max(y,Pk).
Find the maximum possible final value of c.
给定一个正整数 N 和 (1,2,…,N) 的一个排列 P=(P1,P2,…,PN)。
有三个变量 x,y,c,初始时 x=y=c=0。
按 k=1,2,…,N 的顺序,对每个 k 执行以下两种操作之一:
- 操作 1:若 x<Pk,则将 c 增加 1;然后将 x 替换为 max(x,Pk)。
- 操作 2:若 y<Pk,则将 c 增加 1;然后将 y 替换为 max(y,Pk)。
求 c 的最终值所能达到的最大可能值。
输入格式
The input is given from Standard Input in the following format:
N
P1 P2 … PN
输入从标准输入中按以下格式给出:
N
P1 P2 … PN
输出格式
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=4:
- For k=1: Perform operation 1. Then, (x,y,c)=(4,0,1).
- For k=2: Perform operation 1. Then, (x,y,c)=(4,0,1).
- For k=3: Perform operation 2. Then, (x,y,c)=(4,1,2).
- For k=4: Perform operation 2. Then, (x,y,c)=(4,2,3).
- For k=5: Perform operation 2. Then, (x,y,c)=(4,5,4).
c cannot be made greater than 4 no matter how you perform the operations, so output 4.
Constraints
- 1≤N≤5×105
- P is a permutation of (1,2,…,N).
- All input values are integers.
样例 1 解释:
通过执行如下操作,可使 c=4:
- 当 k=1 时:执行操作 1。此时 (x,y,c)=(4,0,1)。
- 当 k=2 时:执行操作 1。此时 (x,y,c)=(4,0,1)。
- 当 k=3 时:执行操作 2。此时 (x,y,c)=(4,1,2)。
- 当 k=4 时:执行操作 2。此时 (x,y,c)=(4,2,3)。
- 当 k=5 时:执行操作 2。此时 (x,y,c)=(4,5,4)。
无论以何种方式执行操作,c 均无法超过 4,因此输出 4。
限制条件
- 1≤N≤5×105
- P 是 (1,2,…,N) 的一个排列。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?