2020 BIT冬训-C++STL J - Hints of sd0061 HDU - 6040

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 mm coming contests. sd0061 has left a set of hints for them.

There are nn noobs in the team, the ii-th of which has a rating aiai. 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+bjbk is satisfied if bibj, 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(1n107,1m100)

The second line contains mm integers, the i-th of which is the number bi of the i-th hint. (0bi<n)

The nn 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 #xx: 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

这题真的是烦……对于寻找正确答案。只需要一个nth_element();函数即可。但对于时间优化
由于bi+bjbkbibj, bi<bk and bj<bk)。所以需要先对b进行排序。
然后倒序从最后一个b开始计算(由于上面的式子,所以这样做的收益是巨大的)
但这样对于2.5s的时间限制来说还是不够。所以我们需要注意到上面的一个约束条件
bibj,然后再特判等于情况,另其中一个直接获得答案。即可大幅减少时间。最终入围!!(ಥ_ಥ) 
AC代码如下(网上有些代码实测是不能AC的(别问我怎么知道的))
#include<stdio.h>
#include<algorithm>
using namespace std;
const int manx = 1e7+5;
unsigned n,m,x,y,z,noobs[manx],id,r;
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;
}
pair<unsigned,int> con[105];
int ans[105];
int main(){
    while(scanf("%d",&n)!=EOF){
        scanf("%d%u%u%u",&m,&x,&y,&z);
        for(int i=0;i<n;i++)
            noobs[i]=rng61();
        for(int i=0;i<m;i++){
            scanf("%u",&con[i].first);
            con[i].second=i;
        }
        sort(con,con+m);
        con[m].first =n,con[m].second=m;
        printf("Case #%d:",++id);
        for(int i=m-1;i>=0;i--){
            if(con[i].first==con[i+1].first)
                ans[con[i].second]=ans[con[i+1].second];
            else{
                nth_element(noobs,noobs+con[i].first,noobs+con[i+1].first);
                ans[con[i].second]=noobs[con[i].first];
            }
        }
        for(int i=0;i<m;i++){
            printf(" %u",ans[i]);
        }
        printf("\n");
    }
}

 



posted @ 2021-02-03 21:12  mikku  阅读(84)  评论(0)    收藏  举报