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 ...
随机推荐
- AngularJS 指令绑定 & 简介
指令中独立scope 的 & 官方说明: 1. 绑定表达式 2. 经常用来绑定回调函数 诡异的地方在于,这个 & 某次听人说在子组件中是不能传值给callback的,好奇查了一下官方文 ...
- BZOJ - Problem 3622 - 已经没有什么好害怕的了
题意: 给定两个序列$a$和$b$,让它们进行匹配,求出使得$a_i > b_j$的个数比$a_i < b_j$的个数恰好多$k$,求这样的匹配方法数 题解: 这题的各种表示有一点相似又截 ...
- UFT12.续期的操作方法
安装完毕UFT后,页面中报install错误,此时报此错误的原因是因为UFT的许可证过期了,解决方法如下: 方法是找到C:\ProgramData目录下的SafeNet Sentinel文件夹将其删除 ...
- 20165301 预备作业三:Linux安装及命令入门
预备作业三:Linux安装及命令入门 VirtualBox虚拟机的安装 在进行安装之前,原本以为有了娄老师的安装教程会是一件很容易的事情.万万没想到,在自己实际动手操作中,还是遇到了许多困难.通过与同 ...
- Construct Binary Tree from Inorder and Postorder Traversal (&&Preorder and Inorder Traversal )——数据结构和算法的基本问题
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...
- html5标签div可绑定键盘事件方法
我们知道键盘事件一般用在input这些可以获取焦点的元素上,但是作为div,尽管官方上说可以绑定键盘事件,但是我写了以后发现不生效,于是找答案. 果然,找到了一个神器:tabindex 它是html5 ...
- C# 字符串提取数字
转自:http://www.cnblogs.com/dolphin-gjh/p/6121792.html 一.使用正则表达式 1 string str = "sztq数字提取123sztq数 ...
- ref:【干货分享】PHP漏洞挖掘——进阶篇
ref:http://blog.nsfocus.net/php-vulnerability-mining/ [干货分享]PHP漏洞挖掘——进阶篇 王陶然 从常见的PHP风险点告诉你如何进行PH ...
- 洛谷P3834 [模板]可持久化线段树1(主席树) [主席树]
题目传送门 可持久化线段树1(主席树) 题目背景 这是个非常经典的主席树入门题——静态区间第K小 数据已经过加强,请使用主席树.同时请注意常数优化 题目描述 如题,给定N个正整数构成的序列,将对于指定 ...
- 路径方案数 [SPFA,拓扑排序]
路径方案数 [题目描述] 给一张无向图,n 个点和 m 条边,cyb 在 1 号点,他要去 2 号点, cyb 可以从 a 走到 b,当且仅当 a 到 2 的最短路,比 b 到 2 的最短路长. 求 ...