Jeronimo's List Gym - 101466J (桶排序)

  先求出原序列,然后桶排序,直接查询即可,sort排序复杂度是n*logn会超时,桶排序是n。还有一秒是跑1e8

#include<bits/stdc++.h>
using namespace std;
const int maxn=3e7+10;
const int mod=3e7;
#define inf 0x3f3f3f3f
int a[maxn],ba[maxn],n,m,q,maxx=-1,minn=inf,tot=0;
int main()
{
    std::ios::sync_with_stdio(false);
    memset(ba,0,sizeof(ba));
    cin>>n>>m>>q;
    for(int i=1;i<=m;i++)
    {
         cin>>a[i];
         ba[a[i]]++;
         maxx=max(maxx,a[i]);
         minn=min(minn,a[i]);
    }
    for(int i=m+1;i<=n;i++)
    {
        a[i]=(a[i-m]+a[i-m+1])%mod;
        ba[a[i]]++;
        maxx=max(maxx,a[i]);
        minn=min(minn,a[i]);

    }
    for(int i=minn;i<=maxx;i++)
    {
        for(int j=1;j<=ba[i];j++)
            a[++tot]=i;

    }
    while(q--)
    {
        int x;
        cin>>x;
        cout<<a[x]<<endl;
    }
    return 0;


}

 

posted @ 2018-08-19 18:44  eason99  阅读(54)  评论(0编辑  收藏  举报