#P10786. [NOI2024] 百万富翁

[NOI2024] 百万富翁

Background

This problem only supports judging in C++. Due to platform limits, submitting with C++14 (GCC 9) will cause CE. Please submit using other C++ versions (C++14 or later is recommended).

Different from NOI’s required submission format, your program should not include the header file richest.h. Also, on the premise that your program includes the vector header, it should declare the following function:

std::vector<int> ask(std::vector<int> a, std::vector<int> b);

Other requirements are the same as NOI’s requirements.

Problem Description

Xiao Y’s bank has NN clients, numbered from 00 to N1N-1. Client ii has a deposit of WiW_i yuan, and all clients’ deposit amounts are pairwise distinct.

Xiao P is Xiao Y’s close partner, and he wants to know which client has the most deposit. Xiao P cannot directly obtain the deposit amounts, but he can send several requests one by one. Each request contains several queries. Each query is an ordered pair (i,j)(i,j), meaning that Xiao P wants to know which of client ii and client jj has more deposit. If Wi>WjW_i>W_j, Xiao Y answers ii, otherwise he answers jj.

Xiao P has upper limits on the number of requests tt and the total number of queries across all requests ss. He wants you to write a program to find the client with the largest deposit.

Input Format

You do not need to, and should not, implement the main function.

You should ensure that the submitted program includes the header file richest.h. You may add the following code at the beginning of your program:

#include "richest.h"

You need to implement the following function:

int richest(int N,int T,int S);
  • NN is the number of clients.
  • TT means that, for the current call, the number of requests tt must not exceed this value.
  • SS means that, for the current call, the total number of queries across all requests ss must not exceed this value.
  • The function should return the index of the client with the largest deposit.
  • For each test point, this function will be called by the interactive library exactly 1010 times.

You can send one request to the interactive library by calling the following function:

std::vector <int> ask(std::vector <int> a, std::vector <int> b);
  • When calling ask, you must ensure that the lengths of parameters aa and bb are the same, and every element in them must be a non-negative integer less than NN, representing all queries in this request.
  • The function returns a std::vector <int> with the same length as aa and bb. Denote it by cc, where c[i]c[i] is the index of the client with the larger deposit between clients a[i]a[i] and b[i]b[i].

The problem guarantees that under the given limits on requests and queries, the interactive library runs in at most 33 seconds. The interactive library’s memory usage is fixed and does not exceed 256256 MiB.

grader.cpp in the problem directory is a reference implementation of the interactive library. The interactive library used in the final tests is different from the reference implementation, so your solution should not rely on how the interactive library is implemented.

You can compile an executable in this problem directory using the following command:

g++ grader.cpp richest.cpp -o richest -O2 -std=c++14 -static

For the compiled executable:

  • The executable will read input from standard input in the following format:
    • The first line contains four non-negative integers N,T,S,RN,T,S,R, where RR is the random seed used by the interactive library to generate testdata.
  • After reading the input, the interactive library will call the function richest 1010 times, and test it on testdata generated from the input parameters. After richest returns, the interactive library will output the following information:
    • In the first 1010 output lines, each line first contains three integers r,t,sr,t,s, indicating the result of that run. Here rr is the return value of richest, and the meanings of tt and ss are as described above, followed by messages about correctness, etc.
    • The 1111-th line contains the overall information of the 1010 runs.

Output Format

Suppose the testdata generated by the executable is N=4N=4, W=[101,103,102,100]W=[101,103,102,100], T=100T=100, S=100S=100. Below is a correct interactive process:

::cute-table{tuack}

Contestant Program Interactive Library Explanation
Call richest(4,100,100) Start testing.
Call ask([0,2],[1,3]) Return [1,2][1,2] W0<W1,W2>W3W_0<W_1,W_2>W_3.
Call ask([0,2,3],[1,1,1]) Return [1,1,1][1,1,1] W0<W1,W2<W1,W3<W1W_0<W_1,W_2<W_1,W_3<W_1.
Finish and return 11 Print interaction result to the screen. Interaction ends, and the result is correct.

In this example, r=1,t=2,s=5r=1,t=2,s=5, which satisfies the limits on requests and queries.

Hint

[Files Provided]

In this problem directory:

  • grader.cpp is a reference implementation of the interactive library.
  • richest.h is a header file; contestants do not need to care about its contents.
  • template_richest.cpp is sample code; contestants may implement their solution based on it.

Please back up all provided files. In the final judging, only richest.cpp in this problem directory will be tested. Modifying files other than this program will not affect the judging result.

[Constraints]

For all testdata, it is guaranteed that all WiW_i are pairwise distinct.

This problem has 22 test points. The score and constraints for each test point are shown in the table below.

::cute-table{tuack}

Test Point ID Score N=N= T=T= S=S=
11 1515 10001\,000 11 499500499\,500
22 8585 10000001\,000\,000 2020 20000002\,000\,000

[Scoring]

Notes:

  • Contestants must not obtain internal information from the interactive library by illegal means, such as trying to directly read the values of array WW, or interacting directly with standard input/output streams. Such behavior will be considered cheating.
  • The interactive library used in the final judging is different from the sample interactive library, and may be adaptive: as long as it does not contradict results previously returned by ask, the final interactive library may dynamically adjust the values of WW.

This problem is first subject to the same limits as traditional problems. For example, a compile error results in 00 points for the whole problem; runtime errors, exceeding the time limit, or exceeding the memory limit will all result in 00 points for the corresponding test point. Contestants may only access variables or data defined by themselves and provided by the interactive library, as well as their corresponding memory. Attempting to access other memory locations may lead to compile errors or runtime errors.

In each call to richest, the number of requests used tt and the total number of queries across all requests ss must be within the corresponding limits; otherwise, you will get 00 points.

Based on the above conditions:

  • In test point 11, you get full score if and only if calls to ask are legal and richest returns the correct answer.
  • In test point 22, your score will be calculated as follows:
    • If any call to ask is illegal, you get 00 points.
    • If all calls to ask are legal, let maxt\max t be the maximum tt among the multiple calls to richest, and let maxs\max s be the maximum ss. Then the program gets 85f(maxt)g(maxs)\lfloor 85 \cdot f(\max t) \cdot g(\max s)\rfloor points, where ff and gg are computed as in the tables below:

::cute-table{tuack}

maxt\max t f(maxt)f(\max t)
maxt8\max t\leq 8 11
9maxt209\leq \max t\leq 20 114maxt81-\dfrac{1}{4}\sqrt{\max t-8}

::cute-table{tuack}

maxs\max s g(maxs)g(\max s)
maxs1099944\max s\leq 1\,099\,944 11
1099945maxs11000431\,099\,945\leq \max s\leq 1\,100\,043 116log10(maxs1099943)1-\dfrac{1}{6} \log_{10} (\max s-1\,099\,943)
1100044maxs20000001\,100\,044\leq \max s\leq 2\,000\,000 $\dfrac{2}{3}-\dfrac{1}{1\,500}\sqrt{\max s-1\,100\,043}$

Below are examples in test point 22 showing how different tt and ss affect the score.

::cute-table{tuack}

maxt\max t maxs\max s Score for Test Point 22
=20=20 1099944\le 1\,099\,944 1111
=19=19 1414
=18=18 1717
=17=17 2121
=16=16 2424
=15=15 2828
=14=14 3232
=13=13 3737
=12=12 4242
=11=11 4848
=10=10 5454
=9=9 6363
8\le 8 [1099974,1099978]\in [1\,099\,974,1\,099\,978]
[1099969,1099973]\in [1\,099\,969,1\,099\,973] 6464
[1099965,1099968]\in [1\,099\,965,1\,099\,968] 6565
[1099962,1099964]\in [1\,099\,962,1\,099\,964] 6666
[1099959,1099961]\in [1\,099\,959,1\,099\,961] 6767
[1099957,1099958]\in [1\,099\,957,1\,099\,958] 6868
[1099955,1099956]\in [1\,099\,955,1\,099\,956] 6969
[1099953,1099954]\in [1\,099\,953,1\,099\,954] 7070
=1099952=1\,099\,952 7171
=1099951=1\,099\,951 7272
[1099949,1099950]\in [1\,099\,949,1\,099\,950] 7373
=1099948=1\,099\,948 7575
=1099947=1\,099\,947 7676
=1099946=1\,099\,946 7878
=1099945=1\,099\,945 8080
1099944\le 1\,099\,944 8585

Translated by ChatGPT 5