博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 658B B. Bear and Displayed Friends(优先队列)
阅读量:5352 次
发布时间:2019-06-15

本文共 4424 字,大约阅读时间需要 14 分钟。

题目链接:

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.

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 ti.

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?

 

Input

The first line contains three integers nk 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 t1, t2, ..., tn (1 ≤ ti ≤ 109) where ti describes how good is Limak's relation with the i-th friend.

The i-th of the following q lines contains two integers typei and idi (1 ≤ typei ≤ 2, 1 ≤ idi ≤ n) — the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.

It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.

 

Output

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.

Examples
input
4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3
output
NO YES NO YES YES
input
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
output
NO YES NO YES
Note

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 (t1 < t2, t3) so friend 1 won't be displayed
  6. "2 1" — Print "NO".
  7. "2 2" — Print "YES".
  8. "2 3" — Print "YES".

 

题意&&思路:

 

1操作加入,2是询问,插入由于是有一定容量的,所以插入值大的话还要把最小的弹出去,用优先队列维护最小值,用flag数组记录是否在队列中,用num记录队列的大小;

 

AC代码:

 

/*2014300227    658B - 18    GNU C++11    Accepted    93 ms    3456 KB*/#include 
using namespace std;const int N=150005;int n,k,q,a,b;int t[N],flag[N];struct node{ friend bool operator< (node n1, node n2) { return n1.priority>n2.priority; } int priority; int cnt;};priority_queue
qu;int main(){ int num=0; memset(flag,0,sizeof(flag)); scanf("%d%d%d",&n,&k,&q); for(int i=1;i<=n;i++) { scanf("%d",&t[i]); } for(int i=0;i
0) { if(num
x.priority) { flag[x.cnt]=0; qu.pop(); node y; y.cnt=b; y.priority=t[b]; qu.push(y); flag[b]=1; } } } else { node y; y.cnt=b; y.priority=t[b]; qu.push(y); flag[b]=1; num++; } } } return 0;}

 

转载于:https://www.cnblogs.com/zhangchengc919/p/5332483.html

你可能感兴趣的文章
Selenium之Web页面滚动条滚操作
查看>>
组合数据类型练习,英文词频统计实例上
查看>>
Uber回馈开源的一些软件
查看>>
day 3 修改haproxy.cfg 作业
查看>>
UIScrollView —— 缩放实现案例(二)
查看>>
【Qt】Qt Linguist介绍【转】
查看>>
sim usim Uim 区别
查看>>
网页中插入透明Flash的方法和技巧
查看>>
动态内存申请函数选择(realloc、malloc 、alloca、 calloc)
查看>>
获取元素属性get_attribute
查看>>
视觉设计师的进化
查看>>
Python/jquery
查看>>
WPF之Binding
查看>>
【BZOJ】【2132】圈地计划
查看>>
Lua 语言基本语法
查看>>
ARM 的Thumb状态测试
查看>>
windows下读取utf-8文件
查看>>
apache 启动不了的排查方法
查看>>
Java有没有goto?
查看>>
(转)makefile 的用法
查看>>