#include<bits/stdc++.h>
using namespace std;
const int maxn = 1 << 20;
int n;
set <int> st[maxn];
int x[maxn];
auto nadi(int id, int height){
auto it = st[height].lower_bound(id);
if(it == st[height].end()) return -1;
return *it;
}
int main(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> x[i];
st[x[i]].insert(i);
}
int sol = 0;
for(int i = 0; i < n; i++){
if(!st[x[i]].count(i)) continue;
sol++;
int pos = i;
while(pos >= 0){
st[x[pos]].erase(pos);
pos = nadi(pos,x[pos]-1);
}
}
cout << sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
49656 KB |
Output is correct |
2 |
Correct |
40 ms |
49860 KB |
Output is correct |
3 |
Correct |
42 ms |
49948 KB |
Output is correct |
4 |
Correct |
43 ms |
49948 KB |
Output is correct |
5 |
Correct |
1780 ms |
90020 KB |
Output is correct |
6 |
Correct |
1952 ms |
94976 KB |
Output is correct |
7 |
Correct |
1524 ms |
94976 KB |
Output is correct |
8 |
Correct |
1538 ms |
94976 KB |
Output is correct |
9 |
Correct |
1730 ms |
94976 KB |
Output is correct |
10 |
Correct |
1725 ms |
94976 KB |
Output is correct |