题目链接:

B. Bear and Displayed Friends

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 <bits/stdc++.h>
using namespace std;
const int N=;
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<node>qu;
int main()
{
int num=;
memset(flag,,sizeof(flag));
scanf("%d%d%d",&n,&k,&q);
for(int i=;i<=n;i++)
{
scanf("%d",&t[i]);
}
for(int i=;i<q;i++)
{
scanf("%d%d",&a,&b);
if(a==)
{
if(flag[b])printf("YES\n");
else printf("NO\n");
}
else
{
if(num>)
{
if(num<k)
{
node y;
y.cnt=b;
y.priority=t[b];
qu.push(y);
flag[b]=;
num++;
}
else
{
node x=qu.top();
if(t[b]>x.priority)
{
flag[x.cnt]=;
qu.pop();
node y;
y.cnt=b;
y.priority=t[b];
qu.push(y);
flag[b]=;
}
}
}
else
{
node y;
y.cnt=b;
y.priority=t[b];
qu.push(y);
flag[b]=;
num++;
}
}
} return ;
}

codeforces 658B B. Bear and Displayed Friends(优先队列)的更多相关文章

  1. 【Codeforces 639A】Bear and Displayed Friends

    [链接] 我是链接,点我呀:) [题意] [题解] 时刻维护一下前K大的数字就好. 因为k<=6 然后数字不会减少只会增加. 因此只要维护一个大小为k的数组就ok. 保证这个数组是有序的. 写个 ...

  2. VK Cup 2016 - Round 1 (Div. 2 Edition) B. Bear and Displayed Friends 树状数组

    B. Bear and Displayed Friends 题目连接: http://www.codeforces.com/contest/658/problem/B Description Lima ...

  3. Codeforces 658B Bear and Displayed Friends【set】

    题目链接: http://codeforces.com/contest/658/problem/B 题意: 给定元素编号及亲密度,每次插入一个元素,并按亲密度从大到小排序.给定若干操作,回答每次询问的 ...

  4. codeforces Codeforces Round #318 div2 A. Bear and Elections 【优先队列】

    A. Bear and Elections time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)

    优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...

  6. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. codeforces 828 C. String Reconstruction(思维+优先队列)

    题目链接:http://codeforces.com/contest/828/problem/C 题解:有点意思的题目,可用优先队列解决一下具体看代码理解.或者用并查集或者用线段树都行. #inclu ...

  8. codeforces 680C C. Bear and Prime 100(数论)

    题目链接: C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. codeforces 680B B. Bear and Finding Criminals(水题)

    题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...

随机推荐

  1. 为备考二级C语言做的代码练习---辅导资料《C语言经典编程282例》--(1)

    因为二级考试的时候用的C语言编译器是VC++6.0 真是日了狗了 用这个编译器 这是我第2个C编译器吧,第一个用的是啊哈C编译器..第二个是VS++6.0 然后在win下用VS2013感觉挺不错的 毕 ...

  2. php迭代器模式

    其实就是遍历数组 然后对数组中的元素进行操作 实现iterator接口即可.

  3. win7查看端口占用

    1.查看谁占用了我们的80端口,在windows命令行窗口下执行:   netstat -aon|findstr 80 发现80端口被进程号为2596的进程占用.2.查看占用80端口进程的应用程序是什 ...

  4. php 字符串内容是数组格式 转换成数组

    一个简单的应用.. 例, $str    =    "array( 'USD'=>'1', 'GBP'=>'0.6494', 'EUR'=>'0.7668' ,'JPY'= ...

  5. Intellj IDEA光标替insert状态,back键无法删除内容

    Intellj IDEA光标为insert状态,无法删除内容导入项目后,发现打开java文件的光标是win系统下按了insert键后的那种宽的光标,并且还无法删除内容,且按删除(delete)键也只见 ...

  6. C#高级编程 第十五章 反射

    (二)自定义特性 使自定义特性非常强大的因素时使用反射,代码可以读取这些元数据,使用它们在运行期间作出决策. 1.编写自定义特性 定义一个FieldName特性: [AttributeUsage(At ...

  7. Objective-C/C++混编编译器设置

    本文转载至 http://blog.csdn.net/yu0089/article/details/8220275 当使用Xcode编写C++代码时,难以避免要使用xcode/C++混合编译. 如果你 ...

  8. python 基础 4.4 生成式 生成器 迭代器

    一.生成式和生成器   列表生成式是python受欢迎的语法之一,通过一句简洁的语法就可以对一组元素进行过滤,还可以对得到的元素进行转换处理.   #/usr/bin/python #coding=u ...

  9. PHP、AJAX综合练习(增、删、改、查、分页、模糊查询)

    先来几张效果图 主页面分页显示: 关键字查询,关键字描红 添加数组,弹出窗口,点击保存,再不刷新页面的同时添加到网页数据 修改界面:弹出窗口,文本框中保留点击的车辆的原始信息 主页面代码 <me ...

  10. Unix环境高级编程—进程控制(三)

    一.解释器文件 解释器文件属于文本文件,起始行形式为: #! pathname[optional-argument] 我们创建一个只有一行的文件如下: #!/home/webber/test/echo ...