A.直接做。
1 #include<vector> 2 #include<cstdio> 3 #include<cstring> 4 #include<iostream> 5 #include<algorithm> 6 #define rep(i,l,r) for (int i=(l); i<=(r); i++) 7 typedef long long ll; 8 using namespace std; 9 10 const int N=100010; 11 int n,m,a[N],cnt[N],tot; 12 vector<int> pos[N]; 13 ll ans; 14 15 int main(){ 16 scanf("%d%d",&m,&n); 17 rep(i,1,n) scanf("%d",&a[i]),pos[a[i]].push_back(i); 18 rep(i,1,m){ 19 if (i>1){ 20 if (pos[i].empty()) ans++; 21 else{ 22 int x=pos[i][0]; 23 if (pos[i-1].empty() || pos[i-1][pos[i-1].size()-1]<x) ans++; 24 } 25 } 26 if (pos[i].empty()) ans++; 27 if (i<m){ 28 if (pos[i].empty()) ans++; 29 else{ 30 int x=pos[i][0]; 31 if (pos[i+1].empty() || pos[i+1][pos[i+1].size()-1]<x) ans++; 32 } 33 } 34 } 35 cout<<ans<<endl; 36 return 0; 37 }