QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#6348. Egor 有个问题

統計

Egor 为训练营想出了一个难题!题目如下:

给定一个包含 $n$ 个正整数的数组 $a$,且数组已按递增顺序排序,请找到 4 个下标 $i < j < p < q$,使得 $a_i \cdot a_q = a_j \cdot a_p$。

他为这个问题编写了校验器:

// returns true if the solution is found,
// returns false if the solution is not found,
// makes the verdict Wrong Answer right away if the found solution is not valid
bool getAnswer(InStream &stream, vector<long long> a) {
string s = stream.readToken("NO|YES"); // PE if the string is not NO or YES
if (s == "NO") return false;
vector<int> b = stream.readInts(4, 1, (int)a.size()); // 4 indices between 1 and n
int i = b[0] - 1, j = b[1] - 1, p = b[2] - 1, q = b[3] - 1; // -1 to make 0-indexed
stream.ensuref(i < j && j < p && p < q, "4 indices should be in increasing order");
stream.ensuref(a[q] / a[p] == a[j] / a[i], "the products are not equal");
return true;
}

乘法运算会超出 long long 的范围,所以 Egor 使用了除法。真聪明!不过现在 Egor 可能又遇到了另一个问题……

输入格式

第一行包含一个整数 $n$ ($4 \le n \le 500\,000$),表示数组的大小。 第二行包含数组 $a_1, a_2, \dots, a_n$ 本身 ($1 \le a_1 < a_2 < \dots < a_n \le 10^{18}$)。

输出格式

如果存在解,第一行输出 “YES”,否则输出 “NO”。 如果存在解,请按顺序输出 4 个选定的下标 $i, j, p, q$,中间用空格隔开。如果存在多个解,输出其中任意一个即可。

样例

样例 1

6
2 6 11 21 47 120
YES
1 3 4 6

样例 2

5
1 2 6 30 210
NO

样例 3

4
7 13 77 143
YES
1 2 3 4

样例 4

4
10 29 31 100
NO

说明

题目中的代码是该问题实际校验器的一个片段。以下是完整代码的链接(带有高亮显示):https://pastebin.com/3ZpNUA6f,密码为:“gkVcB4iqwE”。

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.