ccfcsp-202112-1、序列查询
202112-1 序列查询
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, N;
cin >> n >> N;
vector<int> A(n + 1,0);
vector<int> fa(N + 1,0);
for(int i = 1; i <= n; i++){
cin >> A[i];
}
int j = 1;
int sum = 0;
for(int i = 1; i <= N; i++){
fa[i] = fa[i - 1];
if(j < A.size() && i >= A[j]){
fa[i]++;
j++;
}
if(i == N)
break;
sum += fa[i];
}
cout << sum;
return 0;
}