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

本文介绍了一个关于Codeforces上熊角色Limak与其朋友们互动的问题。主要任务是在朋友陆续上线时,判断特定好友是否出现在屏幕展示的前k名中。通过使用树状数组等数据结构进行高效处理。

B. Bear and Displayed Friends

题目连接:

http://www.codeforces.com/contest/658/problem/B

Description

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

Sample Input

4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3

Sample Output

NO
YES
NO
YES
YES

Hint

题意

有一个人在聊天,现在有n个人,这个屏幕上最多显示k个人,有q次询问。

这个屏幕最多显示k个人,如果有超过k个人在线,那么就只会显示前k个权值最大的人

现在有q次询问,有两个操作

1 x x人上线

2 y 问y在不在屏幕上

题解:

用一个权值树状数组去维护这个人是目前的第几名就好了

不过这道题没有下线操作,所以感觉离线去做更简单一点……

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+6;

int a[maxn];
int lowbit(int x)
{
    return x&(-x);
}
void update(int x,int v)
{
    for(int i=x;i<maxn;i+=lowbit(i))
        a[i]+=v;
}
int get(int x)
{
    int tot = 0;
    for(int i=x;i;i-=lowbit(i))
        tot+=a[i];
    return tot;
}
pair<int,int> C[maxn];
int ha[maxn],flag[maxn];
int main()
{
    int n,k,q;
    scanf("%d%d%d",&n,&k,&q);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        C[i]=make_pair(x,i);
    }
    sort(C+1,C+1+n);
    for(int i=n;i>=1;i--)
        ha[C[i].second]=n-i+1;
    for(int i=1;i<=q;i++)
    {
        int op,x;
        scanf("%d%d",&op,&x);
        if(op==1)
        {
            flag[x]=1;
            update(ha[x],1);
        }
        else
        {
            if(flag[x]==0)
                printf("NO\n");
            else
            {
                int p = get(ha[x]);
                if(p<=k)printf("YES\n");
                else printf("NO\n");
            }
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值