CF599C.Day at the Beach

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.

At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the height of the i-th castle is equal to h__i. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition h__i ≤ h__i + 1 holds for all i from 1 to n - 1.

Squidward suggested the following process of sorting castles:

  • Castles are split into blocks — groups of consecutive castles. Therefore the block from i to j will include castles i, i + 1, ..., j. A block may consist of a single castle.
  • The partitioning is chosen in such a way that every castle is a part of exactly one block.
  • Each block is sorted independently from other blocks, that is the sequence h__i, h__i + 1, ..., h__j becomes sorted.
  • The partitioning should satisfy the condition that after each block is sorted, the sequence h__i becomes sorted too. This may always be achieved by saying that the whole sequence is a single block.

Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements.

一天,章鱼哥、海绵宝宝和派大星决定去海滩玩。不幸的是,天气很糟糕,朋友们无法冲浪。但他们决定用建造沙堡来打发时间。

一天结束时,朋友们共建造了 nn 座沙堡。沙堡编号为 11 到 nn,其中第 ii 座沙堡的高度为 hih_i。当朋友们正准备离开时,章鱼哥注意到沙堡并未按高度有序排列,这看起来很不美观。现在,朋友们打算对沙堡重新排序,使得对所有 ii 从 11 到 n−1n-1,均满足条件 hi≤hi+1h_i \leq h_{i+1}。

章鱼哥提出了如下沙堡排序方案:

  • 将沙堡划分为若干块(blocks)——即若干组连续的沙堡。因此,从第 ii 座到第 jj 座构成的块将包含沙堡 i, i+1, …, ji,\, i+1,\, \dots,\, j。一个块可以仅含一座沙堡。
  • 划分方式需保证每座沙堡恰好属于一个块。
  • 每个块独立于其他块进行排序,即子序列 hi, hi+1, …, hjh_i,\, h_{i+1},\, \dots,\, h_j 将被单独排序。
  • 划分必须满足:在每个块各自排序后,整个序列 hih_i 也变为非递减序列。这一条件总可通过将整个序列视为单一块来实现。

就连派大星都明白,划分出的块数越多,排序过程就越轻松。现在,朋友们请你计算:在满足上述所有要求的前提下,划分所能达到的最大块数。

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day.

The next line contains n integers h__i (1 ≤ h__i ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.

输入的第一行包含一个整数 nn(1≤n≤100 0001 \leq n \leq 100\,000)—— 表示海绵宝宝、派大星和章鱼哥当天用沙子建造的城堡数量。

第二行包含 nn 个整数 hih_i(1≤hi≤1091 \leq h_i \leq 10^9)。其中第 ii 个整数表示第 ii 座城堡的高度。

输出格式

Print the maximum possible number of blocks in a valid partitioning.

输出有效划分中最多可能的块数。

输入输出样例

  • 输入#1

    3
    1 2 3

    输出#1

    3
  • 输入#2

    4
    2 1 3 2

    输出#2

    2

说明/提示

In the first sample the partitioning looks like that: [1][2][3].

In the second sample the partitioning is: [2, 1][3, 2]

在第一个样例中,划分结果如下:[1][2][3]。

在第二个样例中,划分结果为:[2, 1][3, 2]

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

首页