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
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");
}
}
}
}
VK Cup 2016 - Round 1 (Div. 2 Edition) B. Bear and Displayed Friends 树状数组的更多相关文章
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3
C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths
题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors
题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造
D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力
C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) E. Bear and Contribution 单调队列
E. Bear and Contribution 题目连接: http://www.codeforces.com/contest/658/problem/E Description Codeforce ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) D. Bear and Polynomials
D. Bear and Polynomials 题目连接: http://www.codeforces.com/contest/658/problem/D Description Limak is a ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3 构造
C. Bear and Forgotten Tree 3 题目连接: http://www.codeforces.com/contest/658/problem/C Description A tre ...
随机推荐
- weblogic 包里面有中文文件名 会报错
目前:没有解决,只要有中文启动就报错 http://bbs.csdn.net/topics/10055670 http://www.2cto.com/os/201406/311394.html
- KM bfs写法
KM bfs写法 2018astar资格赛的第三题整数规划. 把\(x, y\)看成二分图两边的顶标,\(a_{ij}\)就是二分图的边权,整道题其实就是求二分图的最大权匹配. 然后打了个\(dfs\ ...
- ECNA 2017
ECNA 2017 Abstract Art 题目描述:求\(n\)个多边形的面积并. solution 据说有模板. Craters 题目描述:给定\(n\)个圆,求凸包的周长. solution ...
- 20行js代码制作网页刮刮乐
分享一段用canvas和JS制作刮刮乐的代码,JS部分去掉注释不到20行代码效果如下 盖伦.jpg 刮刮乐.gif HTML部分 <body> ![](img/gailun.jpg) &l ...
- [How to] MapReduce on HBase ----- 简单二级索引的实现
1.简介 MapReduce计算框架是二代hadoop的YARN一部分,能够提供大数据量的平行批处理.MR只提供了基本的计算方法,之所以能够使用在不用的数据格式上包括HBase表上是因为特定格式上的数 ...
- 修改系统时间为UTC时间
1 拷贝时区文件 cp /usr/share/zoneinfo/Etc/GMT /etc/localtime 2 修改/etc/profile 在最后添加 TZ="Etc/GMT" ...
- cvc-complex-type.2.4.a: Invalid content was found starting with element ‘init-param’(转)
在写xml的时候又一次总是报cvc-complex-type.2.4.a: Invalid content was found starting with element 错误,还出现小红叉,在网上找 ...
- bzoj1941 hdu5992
看了青岛赛区的题简单学了一下kd,感觉这东西还是挺厉害的 一般kd树找最近点对最坏是O(n),但是随机情况下跑得还是很快的 kd树是一棵BST,但是每一层的关键字不同 一般写法是按照每一维轮流来,这一 ...
- C#字符串(Sring)操作
//字符串访问 //string s = "ABCD"; //Console.WriteLine(s[0]);//第0位字符 ...
- CodeForces 805E Ice cream coloring
直觉,构造. 画了几个样例,发现可以随便构造......先构造根节点的完全图,每个点置为不同的颜色,然后构造儿子节点的完全图...... #include <cstdio> #includ ...