P27857 [洛谷] [Language Monthly Contest 202307] std::string
普及
题目描述

Problem Background

This is a hack problem. In this problem, you will be given two questions and two pieces of code that solve these questions, but the provided code does not produce correct outputs for certain inputs. Incorrect outputs include:

  1. Outputting incorrect results.
  2. Running out of time.
  3. Producing some runtime undefined behavior. Currently, detectable undefined behavior only includes array out-of-bounds.

For this problem, you need to submit an input dataset that meets the requirements, causing the given code to fail to produce correct outputs. You can use the 'Submit Answer' feature directly, or submit a data generator written in any language.


Hint: If you use the Submit Answer feature, remember to switch the language back to the one you are using when submitting other problems.

Problem Description

Below are the descriptions of the two questions:

Question 1

Input an integer $n$ and output a string consisting of $n$ consecutive $\texttt{HelloLuogu}$.

Question 2

Given a sequence $a$, please divide this sequence into as many segments as possible, such that the bitwise AND sum of each segment is minimized.

Output the maximum number of segments.

Input and Output Format

Input Format

Question 1

The input consists of a single line containing an integer $n$.

Question 2

The first line contains an integer $n$.
The second line contains $n$ integers, where the $i$-th integer represents $a_i$.

Output Format

Question 1

Output a single line containing a string as the answer.

Question 2

Output a single line containing an integer as the answer.

Sample Input and Output

Sample Input #1

2

Sample Output #1

HelloLuoguHelloLuogu

Sample Input #2

5
2 3 1 5 2

Sample Output #2

2

Notes

Sample Sets and Actual Input Notes

The two samples correspond to the sample input and output for the two questions.

If you directly use the 'Submit Answer' method, please name the two input files as 1.in and 2.in, and submit them in a zip archive;

If you use a data generator, your generator can read an integer $x$ from standard input, where $1 \leq x \leq 2$, indicating the problem number for the test point, and then output the corresponding input data.

Obviously, your program should not read any content mentioned in the 'Input Format' (but should construct them), nor should it output any content mentioned in the 'Sample Output' (but only output the constructed input data). You should not use the samples to test your program; these are just examples for the two questions.

Sample 2 Explanation

Divide into two segments: $[2,3,1]$ and $[5,2]$. The bitwise AND of both segments is $0$, and their sum is also $0$, which can be proven to be the minimum sum.

Data Size Requirements

The data you provide must meet the following requirements:

  1. Fully comply with the 'Input Format' regulations, without any extra input, but can have a trailing newline, and for Question 1, can have trailing spaces.
  2. For Question 1, $1 \leq n \leq 10^5$.
  3. For Question 2, $1 \leq n \leq 2 \times 10^5$, $0 \leq a_i \leq 10^9$.

Target Code

You need to hack the following code:

Question 1

#include <iostream>
using namespace std;

int main() {
  int n;
  string ans, base = "HelloLuogu";
  cin >> n;
  while (n--) ans = ans + base;
  cout << ans << endl;
}

Question 2

#include <vector>
#include <iostream>
#include <algorithm>

int T;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  std::cin >> n;
  std::vector<int> a(n + 1), pre(n + 2), post(n + 2);
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  pre[1] = a[1];
  for (int i = 2; i <= n; ++i) pre[i] = pre[i - 1] & a[i];
  post[n] = a[n];
  for (int i = n - 1; i; --i) post[i] = post[i + 1] & a[i];
  int ans = 1;
  for (int i = 1; i < n; ++i) if (pre[i] + post[i + 1] == pre[n]) {
    ++ans;
  }
  std::cout << ans << '\n';
}

The compilation options for the target code are -std=c++14 -fno-asm -O2. The compiler is the g++ provided by Luogu. You can select the C++14 language in the 'Online IDE' to get the exact same compilation environment.

Data Judgment

The data you provide must fully comply with the 'Data Size Requirements'; otherwise, it will result in an Unaccepted outcome.

Timeout Judgment

We will check the program's running time every few instructions. We guarantee that the number of instructions between two checks is a quantity independent of the input size, i.e., we check every $O(1)$ instructions. The number of instructions between two checks will not be too many, generally not exceeding 100 C++ statements.

If the program's running time exceeds $500 \text{ms}$, it is judged as running out of time and returns an accepted result.

Incorrect Result Judgment

If the program ends within the specified time and produces an output, we will compare this output with the completely correct output. If they differ, it is judged as a successful hack, returning an accepted result.

Undefined Behavior Judgment

We will check whether the array index exceeds the array range before each explicit array element access. If it exceeds, it is judged as a successful hack, returning an accepted result.

This means that if you want to hack through undefined behavior, you can only hack explicit array element access.

Sample Program

This is a sample program to help you understand what you need to output, but it cannot produce correct hack data. Submitting this program directly will not earn points.

#include <iostream>

using namespace std;

int main() {
  int taskId;
  cin >> taskId;
  if (taskId == 1) {
    cout << "" <<endl;
  } else if (taskId == 2) {
    cout << "" << endl;
  } else { // This else will not be executed
    cout << "Stupid Fusu!" << endl;
  }
}

If you use the 'Submit Answer' feature, please ensure that opening the zip archive directly shows only the two .in files. This means the file structure must be:

ans.zip
 |---1.in
 |---2.in

The two files should not be contained in an additional folder, i.e., the file structure should not be:

ans.zip
 |---ans(folder)
      |---1.in
      |---2.in

About Evaluation Information

If the hack is successful, the corresponding test point information will be accepted. If other information is returned, it indicates that there is an error with the program itself.

For example, if TLE is returned, it does not mean that the corresponding program was successfully hacked to timeout, but rather that the data generator itself timed out, and the test point does not earn points.

Specifically, returning a UKE result may indicate illegal data (extra content, missing content, or data range not meeting requirements).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2
样例输出
HelloLuoguHelloLuogu