[Offer收割]编程练习赛96 register

Ended

Participants:98

Verdict:Accepted
Score:100 / 100
Submitted:2019-03-17 13:11:54

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
#define MP make_pair
#define PB emplace_back
using namespace std;
typedef long long ll;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0' || ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
const int N=1e5+10;
int n,m,i,a[N],cnt[N];
int main(){
    read(n),read(m);
    for (i=1;i<=m;++i){
        read(a[i]);
        if (i>1){
            int A=a[i-1],B=a[i];
            if (A>B) swap(A,B);
            cnt[A+1]++,cnt[B+2]--;
        }
    }
    for (i=1;i<=n+1;++i) cnt[i]+=cnt[i-1];
    for (i=2;i<=m-1;++i) cnt[a[i]+1]-=1;
    for (i=0;i<=n;++i){
        printf("%d%c",cnt[i+1],i==n?'\n':' ');
    }
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX