Hints of sd0061Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2359 Accepted Submission(s): 713
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.
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 . 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
|
题意:题目给出了一个函数,直接copy就可以了,根据那个函数直接计算出数组a,然后给出了数组b,要你根据数组b对a进行排序 ai 必须是 第bi + 1 大的数
我们对b的下标进行排序得到一个下标数组然后从大到小去扫一遍这个数组 使用 nth_element 函数 (将a组第b[pos[i]]小的数放到数组左边,比他大的放到数组右边)
然后再拿一个答案数组去根据下标数组记录答案
#include<bits/stdc++.h>
using namespace std;
#define N 10001000
unsigned a[N],b[110],ans[110],under[110],x,y,z;
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;
}
unsigned cmp(unsigned x,unsigned y){
return b[x] < b[y];
}
int main(){
unsigned n,m,A,B,C,Case = 1;
while(scanf("%u %u %u %u %u",&n,&m,&A,&B,&C) != EOF){
x = A;
y = B;
z = C;
for(int i = 0;i < m;i++){
scanf("%u",&b[i]);
under[i] = i;
}
for(int i = 0;i < n;i++){
a[i] = rng61();
}
sort(under,under + m,cmp);
under[m] = m;
b[m] = n;
for(int i = m - 1;i >= 0;i--){
nth_element(a,a + b[under[i]],a + b[under[i + 1]]);
ans[under[i]] = a[b[under[i]]];
}//nth_element(a + x,a + z,a + y) 在 x 到 y之间找第z小的元素放到z位置上
printf("Case #%u:",Case++);
for(int i = 0;i < m;i++){
printf(" %u",ans[i]);
}
printf("\n");
}
return 0;
}