codeforces 658B-Bear and Displayed Friends

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

Sample Input

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
熊的每个朋友都有友好度,而且好友列表可显示的数量有限,当上线好友超出限制时,将优先显示友好度更高的好友。最后需要判断某好友是否被显示。难点在于显示数量达到上限时,移除友好度低的好友。

[cpp]  view plain  copy
  1. #include   
  2. #include   
  3. int main()  
  4. {  
  5.     int n,k,q,i,j,p,flag,num,min,mini;  
  6.     int t[150001];//存储友好度  
  7.     int d[7];//存储当前被显示的好友的编号  
  8.     while(scanf("%d %d %d",&n,&k,&q)!=EOF)  
  9.     {  
  10.     j=1;  
  11.     memset(t,0,sizeof(t));  
  12.     memset(d,0,sizeof(d));  
  13.     for(i=1;i<=n;i++)  
  14.         scanf("%d",&t[i]);  
  15.     for(i=1;i<=q;i++)  
  16.         {scanf("%d %d",&flag,&num);  
  17.         if(flag==1)  
  18.         {  
  19.             if(j<=k)  {d[j]=num; j++;}  
  20.             else { //当显示好友数量达到上限时  
  21.            min=t[d[1]];  mini=1;   for(p=1;p<=k;p++) {if(t[d[p]]
  22.            if(min<=t[num]) d[mini]=num;  
  23.             }  
  24.         }  
  25.         if(flag==2)  
  26.         {  
  27.             for(p=1;p<=k;p++)  
  28.              {  if(d[p]==num) {printf("YES\n"); flag=1;  break; }//检测该好友是否被显示  
  29.    }  
  30.  if(flag!=1) printf("NO\n");  
  31.       }  
  32.     }  
  33.    }  
  34.     return 0;  
  35. }  

你可能感兴趣的:(codeforces)