#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=1e18*4;
const ld pai=acos(-1);
int n;
int a[1000009],done[1000009];
set<int>s[1000009];
int main(){
cin>>n;
int num=0;
for(int i=0;i<n;i++)cin>>a[i],s[a[i]].ins(i);
for(int i=0;i<n;i++){
if(done[i])C;
num++;
int crnt=a[i];
int last=i;
while(crnt){
if(s[crnt].lb(last)==s[crnt].end())break;
auto it=s[crnt].lb(last);
done[*it]=1;
last=*it;
s[crnt].era(*it);
crnt--;
}
}
cout<<num<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
47352 KB |
Output is correct |
2 |
Correct |
45 ms |
47352 KB |
Output is correct |
3 |
Correct |
45 ms |
47480 KB |
Output is correct |
4 |
Correct |
47 ms |
47608 KB |
Output is correct |
5 |
Correct |
1419 ms |
90724 KB |
Output is correct |
6 |
Correct |
1788 ms |
95952 KB |
Output is correct |
7 |
Correct |
1383 ms |
87352 KB |
Output is correct |
8 |
Correct |
1257 ms |
87004 KB |
Output is correct |
9 |
Correct |
1410 ms |
89080 KB |
Output is correct |
10 |
Correct |
1444 ms |
90772 KB |
Output is correct |