/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,m,k,cnt;
ll a[1000010];
ll mp[1000010];
ll tek[1000010];
void anomalous_solve()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
mp[a[i]]=i;
}
ll ans=0;
mp[0]=100000000;
vector<ll>v;
for(int i=1;i<=n;i++)
{
//cout<<i<<" ";
v.push_back(i);
if(mp[i]-1==mp[i-1])
{
//cout<<ans<<"!\n";
continue;
}
else
{
//cout<<a[mp[i]-1]<<" "<<mp[a[mp[i]-1]]+1<<" "<<tek[a[mp[i]-1]]<<"___";
if(a[mp[i]-1]<i && mp[a[mp[i]-1]]+1==mp[i] && tek[a[mp[i]-1]]==0)
{
//cout<<ans<<"?\n";
for(int j=a[mp[i]-1]+1;j<i;j++)
{
tek[j]=1;
}
continue;
}
ans++;//cout<<ans<<"|\n";
}
}
cout<<ans;
}
int main()
{
// freopen("INPUT.txt","r",stdin);
// freopen("OUTPUT.txt","w",stdout);
ios_base::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
ll test=1;
//cin>>test;
for(int pos=1;pos<=test;pos++)
anomalous_solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |