CCF20211201——序列查询
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define Max 10000000
int a[Max]={0},b[Max]={0};
int main()
{int n,m;int sum=0,x=0,flag=0;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];}for(int i=0,x=0;i<=n,x<m;x++){if(a[i+1]<=x)i++;if(a[i]<=x&&a[i+1]>x){flag=i;b[x]=flag;}else if(a[n]<=x)b[x]=n;sum+=b[x];}cout<<sum<<endl;return 0;
}