#abc282f. F - Union of Two Sets

F - Union of Two Sets

Score : 500500 points

问题描述

这是一个交互式任务,你编写的程序和裁判程序将通过标准输入和输出进行互动。

你们将遵循以下步骤进行操作。该过程包括阶段1和阶段2,其中阶段1紧接着阶段2执行。

(阶段1)

  • 裁判给出一个整数 NN
  • 你需要打印一个整数 MM,其范围在 115000050000(包含两端点)之间。
  • 你还需要打印 MM 对整数 (l1,r1),(l2,r2),,(lM,rM)(l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M),确保对于所有 i=1,2,,Mi = 1, 2, \ldots, M,满足 1liriN1 \leq l_i \leq r_i \leq N (这 MM 对整数不需要互不相同)。

(阶段2)

  • 裁判给出一个整数 QQ
  • 你与裁判重复以下步骤共 QQ 次。
    • 裁判给出一对查询用的整数 LLRR
    • 你需要回应两个整数 aabb,它们的范围在 11MM(包含两端点)之间(可能有 a=ba = b)。这里,aabb 必须满足以下条件,否则你的提交将被判为错误。
      • 集合 {la,la+1,,ra}\lbrace l_a, l_a+1, \ldots, r_a\rbrace 与集合 {lb,lb+1,,rb}\lbrace l_b, l_b+1, \ldots, r_b\rbrace 的并集等于集合 {L,L+1,,R}\lbrace L, L+1, \ldots, R\rbrace

在完成上述流程后,请立即终止程序以获得正确评判。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

This is an interactive task, where your and the judge's programs interact via Standard Input and Output.

You and the judge will follow the procedure below. The procedure consists of phases 11 and 22; phase 11 is immediately followed by phase 22.

(Phase 11)

  • The judge gives you an integer NN.
  • You print an integer MM between 11 and 5000050000, inclusive.
  • You also print MM pairs of integers (l1,r1),(l2,r2),,(lM,rM)(l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) such that 1liriN1 \leq l_i \leq r_i \leq N for every i=1,2,,Mi = 1, 2, \ldots, M (the MM pairs do not have to be distinct).

(Phase 22)

  • The judge gives you an integer QQ.
  • You and the judge repeats the following QQ times.
    • The judge gives you two integers LL and RR as a query.
    • You respond with two integers aa and bb between 11 and MM, inclusive (possibly with a=ba = b). Here, aa and bb must satisfy the condition below. Otherwise, your submission will be judged incorrect.
      • The union of the set {la,la+1,,ra}\lbrace l_a, l_a+1, \ldots, r_a\rbrace and the set {lb,lb+1,,rb}\lbrace l_b, l_b+1, \ldots, r_b\rbrace equals the set {L,L+1,,R}\lbrace L, L+1, \ldots, R\rbrace.

After the procedure above, terminate the program immediately to be judged correct.

Constraints

  • 1N40001 \leq N \leq 4000
  • 1Q1051 \leq Q \leq 10^5
  • 1LRN1 \leq L \leq R \leq N
  • All values in the input are integers.

Input and Output

This is an interactive task, where your and the judge's programs interact via Standard Input and Output.

(Phase 11)

  • First, NN is given from the input.

  • Next, an integer MM between 11 and 5000050000, inclusive, should be printed.

  • Then, (l1,r1),(l2,r2),,(lM,rM)(l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) should be printed, one at a time. Specifically, for each i=1,2,,Mi = 1, 2, \ldots, M, the ii-th output should be (li,ri)(l_i, r_i) in the following format:

lil_i rir_i

(Phase 22)

  • First, QQ is given from the input.

  • In each query, integers LL and RR representing the query are given in the following format:

LL RR

  • In response to each query, two integers aa and bb should be printed in the following format:

aa bb

Cautions

  • At the end of each output, print a newline and flush Standard Output. Otherwise, you may get the TLE verdict.
  • If your program prints a malformed output or quits prematurely, the verdict will be indeterminate. Particularly, note that in case of a runtime error, the verdict may be WA or TLE instead of RE.
  • After phase 22, immediately terminate the program. Otherwise, the verdict will be indeterminate.
  • LL and RR given in phase 22 will be decided according to (l1,r1),(l2,r2),,(lM,rM)(l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) you print in phase 11.

Sample Interaction

Below is a sample interaction with N=4N = 4 and Q=4Q = 4.

InputOutputDescription
4$N$ is given.
6You print $M$.
3 3You print $(l_1, r_1) = (3, 3)$.
4 4You print $(l_2, r_2) = (4, 4)$.
1 1You print $(l_3, r_3) = (1, 1)$.
2 4You print $(l_4, r_4) = (2, 4)$.
1 3You print $(l_5, r_5) = (1, 3)$.
2 2You print $(l_6, r_6) = (2, 2)$.
4$Q$ is given.
1 3As the first query, $L = 1$ and $R = 3$ are given.
1 5You respond with $a = 1$ and $b = 5$.
3 4As the second query, $L = 3$ and $R = 4$ are given.
2 1You respond with $a = 2$ and $b = 1$.
2 4As the third query, $L = 2$ and $R = 4$ are given.
4 4You respond with $a = 4$ and $b = 4$.
1 1As the fourth query, $L = 1$ and $R = 1$ are given.
3 3You respond with $a = 3$ and $b = 3$.

update @ 2024/3/10 11:50:56