#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ppb pop_back
#define ub upper_bound
#define lb lower_bound
#define clean(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int int
using pii = pair<int,int>;
using ll = long long;
const int maxn = 1e6+5;
const int inf = 2e9;
const int mod = 1e9+7;
int n,a[maxn],ans;
vector<int> occ[maxn],occ2[maxn];
int32_t main () {
//freopen("in","r",stdin); freopen("out","w",stdout);
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
cin >> n;
for(int i=1;i<=n;i++) cin >> a[i] , occ[a[i]].pb(i);
for(int i=1;i<=maxn-5;i++)
if(!occ[i].empty())
reverse(all(occ[i]));
ans = 1;
for(int i=2;i<=n;i++) {
if(occ[a[i]+1].empty() || occ[a[i]+1].back() > i) {
ans++;
continue;
}
occ[a[i]+1].ppb();
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
47340 KB |
Output is correct |
2 |
Correct |
36 ms |
47340 KB |
Output is correct |
3 |
Correct |
35 ms |
47340 KB |
Output is correct |
4 |
Correct |
35 ms |
47340 KB |
Output is correct |
5 |
Correct |
131 ms |
55352 KB |
Output is correct |
6 |
Correct |
157 ms |
55404 KB |
Output is correct |
7 |
Correct |
108 ms |
55532 KB |
Output is correct |
8 |
Correct |
109 ms |
53868 KB |
Output is correct |
9 |
Correct |
121 ms |
55660 KB |
Output is correct |
10 |
Correct |
129 ms |
54816 KB |
Output is correct |