思路
- 如果是连续相同的序列一定需要保留
如果是不连续则记录下来,后面遇到有相同的就删掉其他那些
代码
// Problem: 序列的美观度
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/9983/I
// Memory Limit: 524288 MB
// Time Limit: 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
#define debug(a) cout<<#a<<":"<<a<<"\n"
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=1000010;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;
const double PI=acos(-1.0);
int a[N],ans;
set<int> s;
void solve(){
int n;cin>>n;
rep(i,1,n) cin>>a[i];
rep(i,1,n){
if(s.find(a[i])==s.end()) s.insert(a[i]);
else {
ans++;
if(s.size()>1) {
s.clear();
s.insert(a[i]);
}
}
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;cin>>t;while(t--)
solve();
return 0;
}