# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
106881116 |
Practice:
shao0320 |
1479B2
- 27
|
GNU C++11
|
Wrong answer on test 6
|
15 ms
|
2868 KB
|
2021-02-08 09:29:02 |
2021-02-08 09:29:02 |
|
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define pb push_back
#define N 200005
using namespace std;
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*f;
}
int n,a[N],nxt[N],pos[N];
vector<int>A,B;
int main()
{
n=read();
for(int i=1;i<=n;i++)a[i]=read(),pos[a[i]]=n+1;
for(int i=n;i>=1;i--)
{
if(a[i]!=a[i+1])pos[a[i+1]]=i+1;
nxt[i]=pos[a[i]];
}
A.pb(1);
for(int i=2;i<=n;i++)
{
if(a[i]==a[i-1])continue;
if(a[A[A.size()-1]]==a[i])continue;
else if(B.size()&&a[B[B.size()-1]]==a[i])continue;
else if(!B.size())B.pb(i);
else if(nxt[A[A.size()-1]]<nxt[B[B.size()-1]])B.pb(i);
else A.pb(i);
}
int ans=A.size()+B.size();
//for(int i=0;i<A.size())printf("%d ",A[i]);
printf("%d\n",ans);
return 0;
}
/*
6
1 2 3 1 2 2
6
2 2 1 3 2 2
5
1 1 2 1 1
6
6 5 4 4 3 3
*/
Click to see test details