P29901 [洛谷] [Beginner Contest #10] Hack Problem P
普及
题目描述

Problem Background

This is a hack problem. In this type of problem, you will be given several questions and corresponding codes that solve these questions. However, the provided codes do not produce correct outputs for certain inputs. Incorrect outputs include:

  1. Outputting wrong results.
  2. Exceeding the time limit.
  3. Producing runtime undefined behaviors. Currently, detectable undefined behaviors only include array out-of-bounds.

For each question, you need to submit input data that meets the requirements, causing the given code to fail to produce the correct output. 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

The following provides descriptions for three questions:

Question 1

Given two positive integers $x, y$, ensure that their least common multiple ($\mathrm{lcm}$) does not exceed $10^9$. Calculate their least common multiple.

Question 2

Multiple sets of data, given an array of length $n$ $[a_1, a_2, \dots a_n]$, ensure the array is monotonically increasing. There are $q$ queries, each providing an integer $x$, find how many numbers in the array are less than or equal to $x$.

Question 3

Multiple sets of data, given an array of length $n$ $[a_1, a_2, \dots a_n]$, there are $q$ queries, each providing an integer $x$, find how many numbers in the array are less than or equal to $x$.

Note: Questions $2$ and $3$ differ in whether the array is guaranteed to be increasing and in their data ranges, as detailed below.

Input and Output Formats

Input Format

Question 1

The input consists of a single line with two integers, representing $x$ and $y$ respectively.

Question 2

The first line is an integer $T$, indicating the number of test cases.
Subsequent lines provide input for each case.
For each case, the first line contains two integers, representing the length of array $a$ ($n$) and the number of queries ($q$).
The second line contains $n$ integers, representing $a_1, a_2, \dots a_n$.
The third line contains $q$ integers, representing the $q$ queries for $x$.

Question 3

The first line is an integer $T$, indicating the number of test cases.
Subsequent lines provide input for each case.
For each case, the first line contains two integers, representing the length of array $a$ ($n$) and the number of queries ($q$).
The second line contains $n$ integers, representing $a_1, a_2, \dots a_n$.
The third line contains $q$ integers, representing the $q$ queries for $x$.

Output Format

Question 1

Output a single line with one integer, representing the least common multiple of the two numbers.

Question 2

For each case, output a line with $q$ integers, representing the answers to each query.

Question 3

For each case, output a line with $q$ integers, representing the answers to each query.

Sample Input and Output

Sample Input #1

3 4

Sample Output #1

12

Sample Input #2

2
3 3
5 7 9
7 7 7
3 3
1 2 3
2 2 2

Sample Output #2

2 2 2 
2 2 2 

Sample Input #3

2
3 3
4 4 5
4 5 6
3 3
1 1 3
1 2 3

Sample Output #3

2 3 3
2 2 3

Notes

Sample Cases and Actual Input

The three sample cases correspond to the sample input and output for the three questions.

If you use the 'Submit Answer' method, name the input files as 1.in, 2.in, and 3.in respectively, and submit them in a zip archive.

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

Your program should not read any content mentioned in the 'Input Format', nor should it output any content mentioned in the 'Sample Output'. You should not use the sample cases to test your program; they are merely illustrative.

Data Size Requirements

The data you provide must meet the following requirements:

  1. Fully comply with the 'Input Format', without any extra input, but trailing spaces and end-of-line characters are allowed.
  2. All numbers in the data should be integers.
  3. For Question 1, $1 \leq x, y \leq 10^9$, and you must ensure that the least common multiple of the two numbers does not exceed $10^9$.
  4. For Question 2, $1 \leq T \leq 3$, $1 \leq n, q \leq 10^5$, $1 \leq a_i, x \leq 10^9$.
  5. For Question 3, $1 \leq T \leq 3$, $1 \leq n, q, a_i, x \leq 10^6$.

Target Code

You need to hack the following code:

Question 1

#include <iostream>
#include <algorithm>

int main() {
  int x, y;
  std::cin >> x >> y;
  int ans = x * y / std::__gcd(x, y);
  std::cout << ans << std::endl;
}

Question 2

#include <iostream>
#include <algorithm>

const int maxn = 1000003;

int T;
int n, q;
int a[maxn], b[maxn];

int find(int x) {
  int l = 1, r = n;
  int ans = 0;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (a[mid] <= x) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ans;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  for (std::cin >> T; T; --T) {
    std::cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
      std::cin >> a[i];
    }
    for (int x; q; --q) {
      std::cin >> x;
      std::cout << find(x) << " ";
    }
    std::cout << std::endl;
  }
}

Question 3

#include <iostream>

const int maxn = 1000003;

int T;
int n, q;
int a[maxn], b[maxn];

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  for (std::cin >> T; T; --T) {
    std::cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
      std::cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
      b[a[i]]++;
    }
    for (int i = 1; i < maxn; ++i) b[i] += b[i - 1];
    for (int x; q; --q) {
      std::cin >> x;
      std::cout << b[x] << " \n"[q == 1];
    }
  }
}

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

Scoring Explanation

This problem consists of three test points, corresponding to the three questions. Each question hack success results in the corresponding test point returning accepted.

Data Judgment

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

Time Limit Judgment

The program's execution time is monitored periodically. We guarantee that the number of instructions between two checks is a quantity unrelated to the input size, i.e., $O(1)$ instructions are executed between checks. The number of instructions between checks is not too large, usually not exceeding $100$ C++ statements.

If the program's execution time exceeds $500 \text{ms}$, it is judged as running overtime, returning 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 if 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 if (taskId == 3) {
    cout << "" << endl;
  } else { // This else will not be executed
    cout << "QiHai Nanami" << endl;
  }
}

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

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

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

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

About Evaluation Information

If the hack is successful, the corresponding test point information is accepted. If other information is returned, it indicates that the program itself has errors.

For example, if TLE is returned, it does not mean that the corresponding program was successfully hacked to exceed the time limit, but rather that the data generator itself ran overtime, and the test point does not earn points.

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

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 4
样例输出
12