您的位置:首页 > 其它

Codeforces 639A Bear and Displayed Friends 【STL】

2016-04-08 16:59 519 查看
题目链接:Codeforces 639A Bear and Displayed Friends

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

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 3” — Friend 3 becomes online.

“2 4” — We should check if friend 4 is displayed. He isn’t even online and thus we print “NO”.

“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”.

“1 1” — Friend 1 becomes online. The system now displays both friend 1 and friend 3.

“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

“2 1” — Print “NO”.

“2 2” — Print “YES”.

“2 3” — Print “YES”.

题意:给定n个朋友以及与每个朋友的关系值,要求每次上线的人数不能超过k,否则就把关系值最小的踢下线。q次操作

1 id 表示第id个朋友上线

2 id 查询第id个朋友是否在线

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#define fi first
#define se second
#define ll o<<1
#define rr o<<1|1
#define CLR(a, b) memset(a, (b), sizeof(a))
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MAXN = 2*1e5 + 10;
void add(LL &x, LL y) { x += y; x %= MOD; }
bool vis[MAXN];
int a[MAXN];
struct Node {
int index, v;
friend bool operator < (Node a, Node b) {
return a.v > b.v;
}
};
int main()
{
int n, q, k;
while(scanf("%d%d%d", &n, &k, &q) != EOF) {
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
vis[i] = false;
}
priority_queue<Node> Q; Node now;
while(q--) {
int op, id;
scanf("%d%d", &op, &id);
if(op == 1) {
now.index = id; now.v = a[id];
Q.push(now);
vis[id] = true;
if(Q.size() > k) {
now = Q.top(); Q.pop();
vis[now.index] = false;
}
}
else {
printf(vis[id] ? "YES\n" : "NO\n");
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: