QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 32 MB Points totaux : 120

#17034. 小矮人

Statistiques

白雪公主和 $N$ 个矮人住在森林里。当矮人们去采矿时,白雪公主就在社交网络上闲逛。

每天早上,矮人们排成一条长队,吹着口哨去矿区。白雪公主在他们周围跑来跑去,拍照并上传到她最喜欢的社交网络上。

当矮人们进入矿区后,白雪公主回到他们的房子里整理照片,挑选出好看的照片。每个矮人都戴着一顶有颜色的帽子,一共有 $C$ 种不同的颜色。如果一张照片上超过一半的帽子都是同一种颜色,那么这张照片就是好看的。换句话说,如果照片上有 $K$ 个矮人,且有严格大于 $K / 2$ 个矮人戴着相同颜色的帽子,那么这张照片就是好看的。

写一个程序,对于给定的 $M$ 张照片,检查它们是否好看,如果好看,找出其中占主导地位的颜色。

输入格式

第一行包含两个整数 $N$ 和 $C$($3 \le N \le 300\,000$,$1 \le C \le 10\,000$),分别表示矮人的数量和颜色的数量。

第二行包含 $N$ 个介于 $1$ 和 $C$ 之间(含边界)的整数,表示那天早上矮人们排队时帽子的颜色,按排队的顺序给出。

第三行包含一个整数 $M$($1 \le M \le 10\,000$),表示照片的数量。

接下来的 $M$ 行,每行包含两个整数 $A$ 和 $B$($1 \le A \le B \le N$)。每行描述一张照片。这张照片上包含了从第 $A$ 个到第 $B$ 个的所有矮人。

输出格式

输出 $M$ 行。对于每张照片,如果白雪公主认为这张照片不好看,输出 no;如果她认为好看,输出 yes X,其中 X 是照片中占主导地位的颜色。

数据范围

  • 在占总分 30% 的测试数据中,$M$ 将小于 10。
  • 在另外占总分 30% 的测试数据中,$C$ 将小于 10。

样例

输入样例 1

10 3
1 2 1 2 1 2 3 2 3 3
8
1 2
1 3
1 4
1 5
2 5
2 6
6 9
7 10

输出样例 1

no
yes 1
no
yes 1
no
yes 2
no
yes 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.