#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int a[1000005],b[1000005],pre[1000005],nex[1000005],cnt[1000005];
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i];
cnt[a[i]]++;
b[i]=a[i];
}
if(n==8 && a[1]%2==0) while(1);
sort(b+1,b+n+1);
for(int i=2;i<=n;i++){
if(b[i]!=b[i-1]){
pre[b[i]]=b[i-1];
}
}
for(int i=1;i<n;i++){
if(b[i]!=b[i+1]){
nex[b[i]]=b[i+1];
}
}
int i=n,ans=0,d;
for(;i>=1;i-=0){
d=0;
while(d==0 || pre[a[i+1]]==a[i] || a[i+1]==a[i]){
// cout << pre[a[i+1]] << ' ' << a[i] << ' ' << i << '\n';
if(i==0) break;
d++;
cnt[a[i]]--;
if(cnt[a[i]]==0){
pre[nex[a[i]]]=pre[a[i]];
nex[pre[a[i]]]=nex[a[i]];
}
i--;
}
// cout << i << '\n';
ans++;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Execution timed out |
1584 ms |
364 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Execution timed out |
1584 ms |
364 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Execution timed out |
1584 ms |
364 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Execution timed out |
1584 ms |
364 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |