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. bash的输出多行和vim的全部选择

    使用cat命令加输出符>来在bash脚本里面输出多行文本是最直观的做法. cat >out.file <<EOF start a line ... ... a line aga ...

  2. 每日英语:A Better Way To Treat Anxiety

    Getting up the nerve to order in a coffee shop used to be difficult for 16-year-old Georgiann Steely ...

  3. vuex使用 实现点击按钮进行加减

    //store.js /** * vuex配置 */ import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex); //定义属性(数据) v ...

  4. Git和Repo管理使用简要介绍

    在Linux平台下进行Android系统项目开发时,需要Git或repo管理. 一. Git和Repo的区别: 1. Git:Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的 ...

  5. FreeRtos——移植

    现在准备的简单程序LED灯的工程目录中增加freertos文件夹: 在 source目录下的portable目录下只留下下面的文件夹: 为什么呢? 把对应文件移植在工程中之后,添加头文件路径如下图: ...

  6. Spider Studio 新版本 (20140108) - 优化设置菜单 / 生成程序集支持版本号

    本次更新包含两项改进: 1. 优化了设置菜单, 去掉了一些不必要的浏览器行为设置选项: 取而代之的是在脚本中由用户自行设置: public void Run() { Default.CaptureNe ...

  7. input checkbox 选中问题

    对html控制不熟的人,估计被checkbox的选中问题发愁了,因为input的checkbox只有选中属性 checked='checked' 但是它有另外一个规则就是Request的时候 只有选中 ...

  8. CSS3 实现厉害的文字和输入框组合效果

    最近在忙着弄网站,学到了不少效果,这又是一个厉害的  <html> <head> <meta http-equiv="Content-Type" co ...

  9. csdn 模式识别

    http://blog.csdn.net/liyuefeilong/article/details/45217335 模式识别 http://ceit.ucas.ac.cn/index.php?id= ...

  10. wireshark: no interface can be used for capturing in this system

    ubuntu14.04下使用wireshark找不到网卡... 解决方法: Open a terminal by pressing Ctrl+Alt+T and type the following ...