#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;
set<int> st[1000013];
int arr[1000013];
int ans;
set<int> :: iterator it1,it2;
int main(){
//fri("gir.txt");
//fro("cik.txt");
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>arr[i];
st[arr[i]].insert(i);
}
for(int i=1;i<=n;i++){
if(st[arr[i]].count(i)==0){
continue;
}
else{
ans++;
int pos=i;
it1=st[arr[i]].find(i);
int ctr=arr[i];
while(pos>0){
st[ctr].erase(it1);
it1=st[arr[pos]-1].lower_bound(pos);
if(it1==st[arr[pos]-1].end()){
break;
}
else{
ctr=arr[pos]-1;
pos=*it1;
}
}
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
47352 KB |
Output is correct |
2 |
Correct |
46 ms |
47352 KB |
Output is correct |
3 |
Correct |
46 ms |
47480 KB |
Output is correct |
4 |
Correct |
46 ms |
47580 KB |
Output is correct |
5 |
Correct |
977 ms |
91304 KB |
Output is correct |
6 |
Correct |
1202 ms |
96060 KB |
Output is correct |
7 |
Correct |
921 ms |
87544 KB |
Output is correct |
8 |
Correct |
885 ms |
86876 KB |
Output is correct |
9 |
Correct |
1006 ms |
89488 KB |
Output is correct |
10 |
Correct |
1072 ms |
90752 KB |
Output is correct |