Problem Description
sd0061, the legend of Beihang University ACM-ICPC Team, retired last year leaving a group of noobs. Noobs have no idea how to deal with
m
coming contests.
sd0061 has left a set of hints for them.
There are n noobs in the team, the i -th of which has a rating ai . sd0061 prepares one hint for each contest. The hint for the j -th contest is a number bj , which means that the noob with the (bj+1) -th lowest rating is ordained by sd0061 for the j -th contest.
The coach asks constroy to make a list of contestants. constroy looks into these hints and finds out: bi+bj≤bk is satisfied if bi≠bj, bi<bk and bj<bk .
Now, you are in charge of making the list for constroy.
There are n noobs in the team, the i -th of which has a rating ai . sd0061 prepares one hint for each contest. The hint for the j -th contest is a number bj , which means that the noob with the (bj+1) -th lowest rating is ordained by sd0061 for the j -th contest.
The coach asks constroy to make a list of contestants. constroy looks into these hints and finds out: bi+bj≤bk is satisfied if bi≠bj, bi<bk and bj<bk .
Now, you are in charge of making the list for constroy.
Input
There are multiple test cases (about
10
).
For each test case:
The first line contains five integers n,m,A,B,C . (1≤n≤107,1≤m≤100)
The second line contains m integers, the i -th of which is the number bi of the i -th hint. (0≤bi<n)
The n noobs' ratings are obtained by calling following function n times, the i -th result of which is ai .
For each test case:
The first line contains five integers n,m,A,B,C . (1≤n≤107,1≤m≤100)
The second line contains m integers, the i -th of which is the number bi of the i -th hint. (0≤bi<n)
The n noobs' ratings are obtained by calling following function n times, the i -th result of which is ai .
unsigned x = A, y = B, z = C; unsigned rng61() { unsigned t; x ^= x << 16; x ^= x >> 5; x ^= x << 1; t = x; x = y; y = z; z = t ^ x ^ y; return z; }
Output
For each test case, output "
Case #
x
:
y1
y2
⋯
ym
" in one line (without quotes), where
x
indicates the case number starting from
1
and
yi
(1≤i≤m)
denotes the rating of noob for the
i
-th contest of corresponding case.
Sample Input
3 3 1 1 1 0 1 2 2 2 2 2 2 1 1
Sample Output
Case #1: 1 1 202755 Case #2: 405510 405510
题意:
给你一个序列的递推函数,m次询问,询问这个序列上第bi小的数。
思路:
由于数据太大,不能直接用快排。这时候需要用到一个stl函数(不知道这个函数完全不会做,说的就是我)
nth_element(<#_RandomAccessIterator __first#>, <#_RandomAccessIterator __nth#>, <#_RandomAccessIterator __last#>, <#_Compare __comp#>)
调用函数后保证比第n个数小的数都在前面,比它大的数在后面
还需要用到一个技巧,就是将数组b排序,从大到小调用函数,这样计算完就可以缩小__last
//
// main.cpp
// 1008
//
// Created by zc on 2017/8/2.
// Copyright © 2017年 zc. All rights reserved.
//
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,b[110],id[110];
unsigned x, y, z,s[11000000],ans[110];
unsigned rng61() {
unsigned t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
bool cmp(int u1,int u2)
{
return b[u1]<b[u2];
}
int main(int argc, const char * argv[]) {
int kase=0;
while(~scanf("%d%d%u%u%u",&n,&m,&x,&y,&z))
{
for(int i=0;i<m;i++)
{
scanf("%d",&b[i]);
id[i]=i;
}
sort(id,id+m,cmp);
for(int i=0;i<n;i++) s[i]=rng61();
for(int now,last=n,i=m-1;i>=0;i--,last=now)
{
now=b[id[i]];
if(now==last) ans[id[i]]=ans[id[i+1]];
else
{
nth_element(s, s+now, s+last);
ans[id[i]]=s[now];
}
}
printf("Case #%d:",++kase);
for(int i=0;i<m;i++) printf(" %u",ans[i]);
printf("\n");
}
}