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 }
View Code

相关文章:

  • 2021-10-02
  • 2022-01-11
  • 2022-03-02
  • 2022-02-28
  • 2021-10-31
  • 2021-12-03
  • 2022-02-27
  • 2021-09-07
猜你喜欢
  • 2022-12-23
  • 2021-08-06
  • 2021-07-20
  • 2021-08-02
  • 2021-07-13
  • 2021-06-12
  • 2021-10-19
相关资源
相似解决方案