Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- using namespace std;
- ifstream fin("permutari4.in");
- ofstream fout("permutari4.out");
- const int maxn=1e5+2;
- int n, x, res, pos[maxn];
- int main()
- {
- fin>>n;
- for(int i=1; i<=n; i++)
- {
- fin>>x;
- pos[x]=i;
- }
- int st=pos[1], dr=pos[1];
- res=1;
- for(int i=2; i<=n; i++)
- {
- st=min(st,pos[i]);
- dr=max(dr,pos[i]);
- if(dr-st+1==i)
- {
- res++;
- }
- }
- fout<<res<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement