#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
const int N = 1e6 + 5;
int n, b[N], vis[N], b1[N];
int main(){
cin >> n;
vector <int> a(n+1);
vector <pair<int,int>> v;
for(int i = 1; i <= n; i++){
cin >> a[i];
v.push_back({a[i],i});
}
sort(v.begin(), v.end());
for(int i = 0; i < n; i++){
b[v[i].ss] = i;
}
int cnt = 0;
// for(int i = 1; i <= n; i++){
// if(vis[i] == 0) vis[i] = (++cnt);
// if(i < n and (a[i] == a[i+1] or v[b[a[i]]+1].ff == a[i+1])){
// vis[i+1] = vis[i];
// }
// cout << vis[i] << ' ';
// }
// cout << '\n';
// for(auto i: v){
// cout << vis[i.ss] << ' ';
// }
for(int i = 0; i < n; i++){
if(vis[i] == 0) vis[i] = (++cnt);
if((i < n-1) and (v[i].ss+1 == v[i+1].ss)) vis[i+1] = vis[i];
}
for(int i = 0; i < n; i++){
// cout << vis[i] << ' ';
}
for(int i = 1; i < n; i++){
int a = (b[i]), c = (b[i+1]);
if(c > a and vis[a] != vis[c]) cnt--;
}
cout << cnt << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |