A10339 | Bear and Displayed Friends
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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?
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?
输入格式
The first line contains three integers $n$ , $k$ and $q$ ( $1<=n,q<=150000,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}<=10^{9}$ ) 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.
The second line contains $n$ integers $t_{1},t_{2},...,t_{n}$ ( $1<=t_{i}<=10^{9}$ ) 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.
输出格式
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.
输入输出样例
输入 #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. "1 3" — Friend $3$ becomes online.
2. "2 4" — We should check if friend $4$ is displayed. He isn't even online and thus we print "NO".
3. "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".
4. "1 1" — Friend $1$ becomes online. The system now displays both friend $1$ and friend $3$ .
5. "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
6. "2 1" — Print "NO".
7. "2 2" — Print "YES".
8. "2 3" — Print "YES".
1. "1 3" — Friend $3$ becomes online.
2. "2 4" — We should check if friend $4$ is displayed. He isn't even online and thus we print "NO".
3. "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".
4. "1 1" — Friend $1$ becomes online. The system now displays both friend $1$ and friend $3$ .
5. "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
6. "2 1" — Print "NO".
7. "2 2" — Print "YES".
8. "2 3" — Print "YES".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted