CF639A.Bear and Displayed Friends
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer t__i. The bigger this value is, the better the friendship is. No two friends have the same value t__i.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them — those with biggest t__i.
Your task is to handle queries of two types:
- "1 id" — Friend id becomes online. It's guaranteed that he wasn't online before.
- "2 id" — Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Limak 是一只小北极熊。他喜欢通过社交网络与其他熊联系。他有 n 个朋友,他与第 i 个朋友的关系由一个唯一的整数 ti 描述。该值越大,友谊越深厚。任意两个朋友的 ti 值均不相同。
春天即将来临,熊类的冬眠也已结束。Limak 刚刚醒来并登录了系统。此时他所有的朋友仍在睡觉,因此尚无一人在线。接下来的几个小时内,其中一些(可能全部)朋友将陆续上线,每次一人。
系统会显示当前在线的朋友。屏幕上最多可显示 k 位朋友。若当前在线的朋友数超过 k 人,则系统仅显示其中关系最好的 k 位——即 ti 值最大的那 k 位。
你需要处理两类查询:
"1 id"—— 编号为id的朋友上线。保证该朋友此前未在线。"2 id"—— 查询编号为id的朋友当前是否被系统显示。在单独一行中输出"YES"或"NO"。
你能否帮助 Limak 并回答所有第二类查询?
输入格式
The first line contains three integers n, k and q (1 ≤ n, q ≤ 150 000, 1 ≤ k ≤ min(6, n)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers _t_1, _t_2, ..., t__n (1 ≤ t__i ≤ 109) where t__i describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers type__i and id__i (1 ≤ type__i ≤ 2, 1 ≤ id__i ≤ n) — the i-th query. If type__i = 1 then a friend id__i becomes online. If type__i = 2 then you should check whether a friend id__i is displayed.
It's guaranteed that no two queries of the first type will have the same id__i becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (type__i = 2) so the output won't be empty.
第一行包含三个整数 n、k 和 q(1 ≤ n, q ≤ 150000,1 ≤ k ≤ min(6, n)),分别表示朋友的数量、最多显示的在线朋友数量以及查询次数。
第二行包含 n 个整数 t1, t2, ..., tn(1 ≤ ti ≤ 109),其中 ti 描述了 Limak 与第 i 位朋友的关系亲密程度。
接下来的 q 行中,第 i 行包含两个整数 typei 和 idi(1 ≤ typei ≤ 2,1 ≤ idi ≤ n),表示第 i 个查询。若 typei=1,则表示朋友 idi 变为在线状态;若 typei=2,则需判断朋友 idi 是否被显示。
保证不会有两个类型为 1 的查询具有相同的 idi(因为一位朋友不能两次变为在线)。同时,保证至少存在一个类型为 2 的查询(即 typei=2),因此输出非空。
输出格式
For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
对于每个第二类查询,请输出一行答案:如果给定的朋友正在显示中,则输出 “YES”(不带引号),否则输出 “NO”(不带引号)。
输入输出样例
输入#1
4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3
输出#1
NO YES NO YES YES
输入#2
6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3
输出#2
NO YES NO YES
说明/提示
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
- "1 3" — Friend 3 becomes online.
- "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
- "2 3" — We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
- "1 1" — Friend 1 becomes online. The system now displays both friend 1 and friend 3.
- "1 2" — Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (_t_1 < _t_2, _t_3) so friend 1 won't be displayed
- "2 1" — Print "NO".
- "2 2" — Print "YES".
- "2 3" — Print "YES".
在第一个样例中,Limak 有 4 位朋友,初始时全部处于离线状态。最初,系统不显示任何人,因为此时无人在线。接下来共有如下 8 个查询:
- “1 3” —— 第 3 位朋友变为在线。
- “2 4” —— 我们需要检查第 4 位朋友是否被显示。他甚至尚未在线,因此输出 “NO”。
- “2 3” —— 我们需要检查第 3 位朋友是否被显示。此时他是唯一在线的朋友,系统会显示他,因此输出 “YES”。
- “1 1” —— 第 1 位朋友变为在线。此时系统显示第 1 位和第 3 位朋友。
- “1 2” —— 第 2 位朋友变为在线。现在共有 3 位朋友在线,但题目给定 k = 2,因此最多只能显示两位朋友。Limak 与第 1 位朋友的关系比与其他两位在线朋友(第 2、3 位)更差(即 _t_1 < _t_2, _t_3),因此第 1 位朋友不会被显示。
- “2 1” —— 输出 “NO”。
- “2 2” —— 输出 “YES”。
- “2 3” —— 输出 “YES”。
输入解题思路,AI测评打分。不知道怎么写?