###### Codeforces Round #332 (Div. 2)C. Day at the Beach（好题，）

Let’s take a minute to see how the best answer should look like. Let
Hi be a sorted sequence of hi. Let E — set of indices of the last
elements of each block. Then e E, first e sorted elements of sequence
hi are equal to the first e elements of the sequence Hj. So, it is not
difficult to notice that the size of E is the answer for the problem.
Firstly, we need to calculate two arrays: prefmax and suffmin, where
prefmaxi — maximum between a1, a2, …, ai, and suffmini — minimum
between ai, ai + 1, …, an. If you want to get the answer, just
calculate the number of indices i that prefmaxi  ≤  suffmini + 1.
Time: O(N)


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define X first
#define Y second
#define cl(a,b) memset(a,b,sizeof(a))
typedef pair<int,int> P;
const int maxn=100005;
const LL inf=1LL<<45;
const LL mod=1e9+7;
LL a[maxn],suffMax[maxn],suffMin[maxn];
int main(){
int n;scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
for(int i=1;i<=n;i++){
suffMax[i]=max(suffMax[i-1],a[i]);
}
suffMin[n+1]=inf;
for(int i=n;i>=1;i--){
suffMin[i]=min(suffMin[i+1],a[i]);
}
suffMin[1]=inf;
LL ans=0;
for(int i=1;i<=n;i++){
if(suffMax[i]<=suffMin[i+1])ans++;
}
printf("%lld\n",ans);
return 0;
}



#### Codeforces Round #471 div.2 ABC题解

2018-03-24 14:16:58

#### Codeforces Round #482 (Div. 2)

2018-05-15 12:51:24

#### Codeforces Round #464 (Div. 2) C. Convenient For Everybody

2018-02-17 22:12:51

#### Codeforces Round #465 (Div. 2) C. Fifa and Fafa(圆问题，数论)

2018-02-20 16:16:48

#### Codeforces Round #475 (Div. 2) C. Alternating Sum(求逆元)

2018-04-18 09:29:30

#### Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence (构造 贪心)

2017-11-20 13:19:26

#### Codeforces Round #143 (Div. 2) (ABCD 思维场)

2015-07-18 18:58:10

#### Codeforces Round #377 (Div. 2)C. Sanatorium(贪心）

2016-10-26 20:08:59

#### Codeforces Round #465 (Div. 2) D. Fafa and Ancient Alphabet

2018-02-20 04:30:43

#### Educational Codeforces Round 38 (Rated for Div. 2) B. Run For Your Prize

2018-02-17 13:35:37

## 不良信息举报

Codeforces Round #332 (Div. 2)C. Day at the Beach（好题，）