Bear and Displayed Friends

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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 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 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

其实没必要用优先队列的

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <queue> using namespace std;
#define MAX 150000
int n,k,q1;
struct Node
{
int pos;
int value;
friend bool operator <(Node a,Node b)
{
return a.value>b.value;
}
}a[MAX+5];
int tag[MAX+5];
int main()
{
int x,y;
scanf("%d%d%d",&n,&k,&q1);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].value);
a[i].pos=i;
}
priority_queue<Node> q;
memset(tag,0,sizeof(tag));
for(int i=1;i<=q1;i++)
{
scanf("%d%d",&x,&y);
if(x==1)
{
if(q.size()<k)
{
q.push(a[y]);
tag[y]=1;
}
else
{
Node term=q.top();
if(a[y].value>term.value)
{
q.pop();
tag[term.pos]=0;
q.push(a[y]);
tag[y]=1;
}
}
}
else if(x==2)
{
if(tag[y])
printf("YES\n");
else
printf("NO\n");
} }
return 0;
}

CodeForces 639 A的更多相关文章

  1. Codeforces Round #639 (Div. 2)

    Codeforces Round #639 (Div. 2) (这场官方搞事,唉,just solve for fun...) A找规律 给定n*m个拼图块,每个拼图块三凸一凹,问能不能拼成 n * ...

  2. [Codeforces 639B] Bear and Forgotten Tree 3

    [题目链接] https://codeforces.com/problemset/problem/639/B [算法] 当d > n - 1或h > n - 1时 , 无解 当2h < ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. ubuntu下修改读写权限

    把home下所有文件所有者改成输入目标 $ chown - R [your name].users /home/

  2. [sh]shell脚本栗子

    我会定期的把看到的一些好的shell和py脚本搜集在这里,供参考学习: 命令行回收站 推荐一个不相关的:trash-cli,就是命令行版的回收站,它的神奇之处在于不是简单的把文件移动到回收站,而且可以 ...

  3. jquery衬衣产品内容详情页

    html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  4. 实战 Lucene,第 1 部分: 初识 Lucene (zhuan)

    http://www.ibm.com/developerworks/cn/Java/j-lo-lucene1/ ******************************************** ...

  5. 读取SD卡中的图片

    Touxiang=(ImageView)view.findViewById(R.id.Touxiang); //头像Bitmap bm = BitmapFactory.decodeFile(" ...

  6. VS中C#读取app.config数据库配置字符串的三种方法(转)

    关于VS2008或VS2005中数据库配置字符串的三种取法 VS2008建立Form程序时,如果添加数据源会在配置文件 app.config中自动写入连接字符串,这个字符串将会在你利用DataSet, ...

  7. sqlite3命令读出sqlite3格式的文件内容案例

    /*********************************************************************  * Author  : Samson  * Date   ...

  8. 虚拟化–操作系统级 LXC Linux Containers内核轻量级虚拟化技术

    友情提示:非原文链接可能会影响您的阅读体验,欢迎查看原文.(http://blog.geekcome.com) 原文地址:http://blog.geekcome.com/archives/288 软 ...

  9. python手册

    https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/

  10. sql 追踪 神器

    http://www.thinkphp.cn/download/690.html 一个中国人开发的php工具箱此工具能几秒钟追踪出sql 数据库操作, 能分析出 Thinkphp3.2 的任意sql ...