题意:
求把一个序列分成最多个小序列之后,每个进行排序后,序列还是有序的
分析:
f[i]:=a1⋯ai的最大值
g[i]:=ai⋯an的最小值
我们发现如果fi<=gi+1那么ai和之前截断的位置被分开的话,序列还能维持有序性,然后扫一遍就好了
代码:
//
// Created by TaoSama on 2015-11-21
// Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, a[N], f[N], g[N];
int main() {
#ifdef LOCAL
freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
while(scanf("%d", &n) == 1) {
for(int i = 1; i <= n; ++i) {
scanf("%d", a + i);
f[i] = max(f[i - 1], a[i]);
}
g[n + 1] = INF;
for(int i = n; i; --i)
g[i] = min(g[i + 1], a[i]);
int ans = 0;
for(int i = 1; i <= n; ++i) {
// pr(f[i]); prln(g[i + 1]);
if(f[i] <= g[i + 1]) ++ans;
}
printf("%d\n", ans);
}
return 0;
}