CF-1022-C. Neo's Escape · znzryb
## 思路讲解
就是要注意到,如果一段连续的相同的数字是不会影响结果的,因此需要把他们缩减。
## AC代码
::: 源代码
```cpp
// Problem: C. Neo's Escape
// Contest: Codeforces - Codeforces Round 1022 (Div. 2)
// URL: https://codeforces.com/contest/2108/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// by znzryb
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fi first
#define se second
#define pb push_back
#define SZ(a) ((int) a.size())
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef pair<ll,ll> pll;
typedef array<ll,2> arr;
typedef double DB;
typedef pair<DB,DB> pdd;
typedef pair<ll,bool> plb;
constexpr ll MAXN=static_cast<ll>(1e6)+10,INF=static_cast<ll>(5e18)+3;
constexpr ll mod=static_cast<ll>(1e9)+7;
ll N,M,K,T,A[MAXN],uA[MAXN];
// unordered_map<ll,ll> Pos;
inline void solve(){
cin>>N;
set<ll> reaches;
// Pos.clear();
A[0]=0,A[N+1]=0;
priority_queue<arr> pq;
FOR(i,1,N){
cin>>A[i];
// pq.push({A[i],i});
}
ll idx=0,up=0;
FOR(i,1,N){
if(up!=A[i]){
up=A[i];
uA[++idx]=A[i];
pq.push({A[i],idx});
}
}
ll ans=0;
while(!pq.empty()){
ll pos=pq.top()[1];
pq.pop();
if(reaches.find(pos)==reaches.end()){
++ans;
reaches.insert(pos+1);
reaches.insert(pos-1);
}else{
reaches.insert(pos+1);
reaches.insert(pos-1);
}
}
cout<<ans<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--){
solve();
}
// solve();
return 0;
}
/*
AC https://codeforces.com/contest/2108/submission/318060392
*/
```
:::
## 心路历程(WA,TLE,MLE……)
[https://codeforces.com/contest/2108/submission/317973413](https://codeforces.com/contest/2108/submission/317973413)
```cpp
1
3
11 10 10
```