#P10204. [湖北省选模拟 2024] 白草净华 / buer

    ID: 11380 远端评测题 1500ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2024交互题Special JudgeO2优化湖北

[湖北省选模拟 2024] 白草净华 / buer

Background

Due to limitations of the Luogu judging environment, please do not submit this problem using the C++ 14 (GCC 9) language, otherwise it may cause compilation errors.

This is an interactive problem.

The gods only gave humans the knowledge to fill their stomachs, yet humans used it to make tools, write words, and grow their city-states. Now they look toward the stars and the abyss...

At every moment they are creating brand-new “knowledge”, and it makes it impossible for me to look away.

I used to think I was good at asking and answering questions, but I gradually understood that many people pretend to be confused even when they understand. The answer to a question cannot help them. As we grow older, do we all lose the courage to face questions and answers...?

Problem Description

The knowledge of the God of Wisdom, Buer, can be represented by a sequence of length NN: a0,a1,,aN1a_0,a_1,\cdots,a_{N-1} (note that indices start from 00). Unfortunately, mortals cannot窥探 (kuitan, “peer into”) the god’s knowledge: you do not know the value of NN, nor do you know any value aia_i.

The God of Wisdom is kind, and Nahida is willing to tell you everything about this knowledge:

  • For any 0i<N0 \le i < N, aia(i+1)modNa_i \neq a_{(i+1)\bmod N}.
  • There exists one and only one i(0i<N)i(0 \le i < N) such that both ai>a(i+1)modNa_i>a_{(i+1)\bmod N} and ai>a(i+N1)modNa_i > a_{(i+N-1)\bmod N} hold at the same time.

You may ask the God of Wisdom questions. In each query, you may give Nahida an integer kk in the range 01090\sim10^9, and Nahida will answer with the value of a(d+k)modNa_{(d+k)\bmod N}. Here, dd is the index of the element returned by Nahida in the previous query. The initial value of dd is set to 00. For example, if N=5N=5 and you give Nahida 1,2,31,2,3 in order, then the returned values are a1,a3,a1a_1,a_3,a_1 in order.

You have 333333 chances to query. You need to find the maximum value in the sequence aa.

Do you still have the courage to question and to ask?

Implementation Details

The interaction library provides the following functions. You need to declare these functions in your program, but you should not implement their function bodies:

int ask(int k);
  • This function returns the value of a(d+k)modNa_{(d+k)\bmod N} and updates dd to d+kd+k.
int cheat();
  • This function returns the value of NN.
  • If you call this function, you will not be able to get full score for the test point. See the scoring section for details.

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

int buer(int T);
  • T indicates the test point ID.
  • When the function ends, you need to return the maximum value of the sequence aa.

In addition, your submitted program must not try to read from or write to any file or standard streams. Otherwise, you will get 00 points for this problem. Your program needs to include all required headers and namespaces.

In the final test, for each test point, the interaction library will call the buer function exactly once, and use its return value as the result of your program.

Below is a sample program. It gets a1a9a_1 \sim a_9 and returns max(a1,a2)\max(a_1,a_2). You may continue implementing this problem based on it.

#include <vector>
using std::max;
using std::vector;
// Include needed functions from required headers and namespaces.
int ask(int k);
int cheat(); 
// Declare ask and cheat.
int buer(int T) {
	vector <int> vec;
	for(int i = 1; i <= 9; i++) {
		int p = ask(1);
		vec.push_back(p);
	}
	return max(vec[0], vec[1]);
}

It is guaranteed that if the number of calls to ask does not exceed 33333333, the time needed for the interaction library to run in the final test does not exceed 0.20.2 seconds, and the memory used by the interaction library itself does not exceed 1010 MiB.

How to Run the Test Program

A reference implementation of the interaction library, grader.cpp, is provided in the problem directory. The interaction library used in the final test is different from this one, so your solution must not rely on the specific implementation details of the interaction library.

After you implement buer.cpp, put grader.cpp and buer.cpp in the same directory, and compile them into an executable using the following commands:

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

In the commands above, the first line compiles grader.cpp into the object file grader.o, the second line compiles buer.cpp into the object file buer.o, and the third line links grader.o and buer.o to generate the executable buer.

The executable buer compiled in the above way runs as follows:

  • The executable reads testdata from buer.in in the following format:

    • The first line contains two positive integers N,TN,T, representing the length of aa and the test point ID.
    • The second line contains NN positive integers a0,a1,,aN1a_0,a_1,\ldots,a_{N-1}, representing the sequence aa.
  • If your program finishes normally, the executable writes the following to buer.out:

    • Output one line with two integers, representing the number of queries you made and the return value of the buer function.

When debugging, you need to ensure that the input to the executable buer satisfies the format above. Otherwise, the interaction library is not guaranteed to run correctly.

Input Format

Your submitted program must not try to read from or write to any file or standard streams.

Output Format

Your submitted program must not try to read from or write to any file or standard streams.

4 0
1 2 3 2
3

Hint

Sample Explanation 1

In the sample input provided for this problem, the first line contains two integers N,TN,T, representing NN and the test point ID. The sample test point IDs are all 00. The second line contains NN integers a0,a1,,aN1a_0,a_1,\cdots,a_{N-1}, representing the sequence aa. The sample output is one line with one positive integer, representing the maximum value in the sequence aa.

Please note that your program must not try to read from or write to any file or standard streams.

Scoring

The final evaluation will only take buer.cpp. Please do not submit any other files in the contestant directory.

This problem will first be subject to the same limits as traditional problems, for example, a compilation error will cause the whole problem to score 00 points, and runtime errors, exceeding the time limit, exceeding the memory limit, etc. will cause the corresponding test point to score 00 points.

Besides the conditions above, in a test point, if your program makes an illegal function call or the buer function returns a wrong answer, then that test point will get 00 points. Otherwise, suppose your program calls the ask function QQ times:

  • If 0Q3330 \le Q \le 333 and the cheat function is not called, the test point scores 55 points.

  • If 333<Q3333333<Q\le 3333 and the cheat function is not called, the test point scores 33 points.

  • If 0Q3330\le Q \le 333 but the cheat function is called, the test point scores 22 points.

  • If 333<Q3333333<Q\le 3333 but the cheat function is called, the test point scores 11 point.

  • If Q>3333Q>3333, the test point scores 00 points.

Subtasks

For all testdata, it is guaranteed that 2N1062 \le N \le 10^6, 1ai1091 \le a_i \le 10^9.

Test point ID NN\le
11 333333
2202\sim 20 10610^6

Translated by ChatGPT 5