BestCoder Round #62 (div.2) 1004

好长时间没做比赛了,原来就菜现在更菜,1004的题目没想到div.2赛后只有一个人做出来,做题的时候想到了做法但时间不多自己的奇葩代码不足以在比赛时间debug出来,赛后补了一发:

题目&提交地址在这:http://acm.hdu.edu.cn/showproblem.php?pid=5565

 

const int INF = 1000000000;
const double eps = 1e-8;
const int maxn = 10000000 + 10;
const int mod = 1000000000 + 7;
int n,q;
long long seed;
int rand(int l, int r) {
    static long long mo=1e9+7, g=78125;
    return l+((seed*=g)%=mo)%(r-l+1);
}
int num[maxn];
long long  snum[maxn];
long long sum[maxn];
int sumnum[maxn];
struct pp{
    int id;
    int v;
}a[maxn];
bool cmp(pp p1 ,pp p2){
    return p1.v < p2.v;
}
bool cmp1(pp p1,pp p2){
    return p1.id < p2.id;
}
int main() 
{
    //freopen("in.txt","r",stdin);
    int T;
    scanf("%d",&T);
    while(T--){
        clr(num);
        clr(snum);
        clr(sumnum);
        scanf("%d%d%I64d",&n,&q,&seed);
        int ssum=rand(q, 10000000);
        for(int i=1; i<=n; i++) {
            a[i].v=rand(0, ssum/(n-i+1));
            a[i].id = i;
            ssum-=a[i].v;
        }
        a[rand(1, n)].v+=ssum;
        //repf(i,1,n) cout<<a[i].v<<endl;
        //cout<<"...."<<endl;
        sort(a+1,a+n+1,cmp);
        int nn = 1;
        int cmpp = a[n].v;
        num[nn]++;
        snum[nn] = a[n].v;
        repd(i,n-1,1){
            if(a[i].v == cmpp) num[nn]++;
            else{
                nn++;
                num[nn]++;
                cmpp = a[i].v;
                snum[nn] = a[i].v;
            }
        }
        //cout<<"num "<<nn<<endl;
        sumnum[0] = 0;
        sum[0] = 0;
        repf(i,1,nn) sumnum[i] = sumnum[i-1] + num[i];
        repf(i,1,nn-1) sum[i] = sum[i-1] + (snum[i] - snum[i+1])*sumnum[i];
        sum[nn] = sum[nn-1] + sumnum[nn]*snum[nn]; 
      //  cout<<"total "<<sum[nn]<<endl;
       // cout<<"first "<<sum[1]<<endl;
        int id = 0;
        repf(i,1,nn){
            if(q <= sum[i]){
                id = i;
                break;
            }
        }
        repf(i,1,n) if(a[i].v > snum[id]) a[i].v = snum[id];
        int left = (q - sum[id - 1])%sumnum[id];
        int tt = (q - sum[id - 1])/sumnum[id];
        int cc = snum[id] - tt;
        repf(i,1,n) if(a[i].v == snum[id]) a[i].v-=tt;
        sort(a+1,a+1+n,cmp1); 
        repf(i,1,n) if(a[i].v == cc){
            if(left) left--,a[i].v--;
            else{
                break;
            }
        }
        //repf(i,1,n) cout<<a[i].v<<endl;
        if(q  >= sum[nn]) repf(i,1,n) a[i].v = 0;
        int ans = a[1].v + a[1].id;
        repf(i,2,n)   ans ^= (a[i].v + a[i].id);
        printf("%d\n",ans);
    }
    return 0;
}

 

posted on 2015-11-14 22:31  keep trying  阅读(149)  评论(0编辑  收藏  举报

导航