QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100 交互 可 Hack ✓

#1894. 猜数组

统计

这是一个交互式问题。你的程序将通过标准输入和输出与评测程序进行交互。

Alice 和 Bob 决定玩一个名为“猜数组”的游戏。游戏规则非常简单:Alice 有一个包含 $n$ 个整数的数组,Bob 需要通过不超过 $n$ 次关于区间和的询问来猜出这个数组。

在一次移动中,Bob 可以向 Alice 进行以下两种询问之一:

  1. “? l r”:查询数组中从第 $l$ 个元素到第 $r$ 个元素(包含两端)的区间和;
  2. “!”:告诉 Alice 他准备好给出答案了。在此询问后,Alice 期望 Bob 输出 $n$ 个整数:即初始数组。

对于每次第一种类型的询问,Alice 会告诉 Bob 所请求区间的数字之和。但为了增加猜测难度,在每次询问后,Alice 会封锁一个区间。在后续的询问中,Bob 不能查询被封锁区间的数字之和。

请帮助 Bob 通过不超过 $n$ 次第一类询问猜出 Alice 的数组。

交互格式

输入的第一行包含一个整数 $n$ —— Alice 数组的大小($1 \le n \le 10^4$)。保证数组中所有数字的绝对值不超过 $10^9$。

接下来,执行与评测程序(交互器)的通信协议。

交互器期望你的程序发出两种类型的请求:“? l r” 和 “!”,其中 $l, r$ 是你想要查询区间和的整数边界($1 \le l \le r \le n$)。每次查询后必须换行。如果你的程序不遵循查询格式,你的解可能会得到任何判决(除 OK 外)。

在进行第一类查询后,你必须从标准输入读取三个整数 $s, l_b$ 和 $r_b$ —— 所请求区间的和 $s$ 以及新的被封锁区间 $[l_b, r_b]$,之后不能再请求该区间的和($|s| \le 10^{18}; 1 \le l_b \le r_b \le n$)。

第二类查询意味着你的程序准备好给出答案了。在进行第二类查询后,你应该输出 $n$ 个整数来猜测初始数组。

注意,你的程序最多只能进行 $n$ 次第一类查询。如果超过此限制,或者你尝试查询之前被封锁的区间之和,交互器将打印 “-1 -1 -1” 并以 WA 判决退出。为避免获得 TL 或 IL 判决,你的程序在从输入读取到 “-1 -1 -1” 后应以零退出码终止。

样例

输入 1

3
1 2 2
3 2 3
6 1 2

输出 1

? 1 1
? 3 3
? 1 3
!
1 2 3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.