#include <bits/stdc++.h>
#define int long long
using namespace std;
int b[1000001];
int cnt[1000001];
signed main()
{
int n;
cin >> n;
int a[n];
for(int i=0; i < n; i++)cin>>a[i];
for(int i=n-1; i >= 0;i--){
cnt[a[i]]++;
b[i]=cnt[a[i]-1];
if(cnt[a[i]-1]>0)cnt[a[i]-1]--;
}
int rez=0;
for(int i=0; i < n; i++){
if(b[i]==0)rez++;
}
cout<<rez<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
128 ms |
14676 KB |
Output is correct |
6 |
Correct |
132 ms |
15796 KB |
Output is correct |
7 |
Correct |
108 ms |
14328 KB |
Output is correct |
8 |
Correct |
104 ms |
14160 KB |
Output is correct |
9 |
Correct |
116 ms |
14572 KB |
Output is correct |
10 |
Correct |
116 ms |
14676 KB |
Output is correct |