CodeForces 639 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
其实没必要用优先队列的
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
#define MAX 150000
int n,k,q1;
struct Node
{
int pos;
int value;
friend bool operator <(Node a,Node b)
{
return a.value>b.value;
}
}a[MAX+5];
int tag[MAX+5];
int main()
{
int x,y;
scanf("%d%d%d",&n,&k,&q1);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].value);
a[i].pos=i;
}
priority_queue<Node> q;
memset(tag,0,sizeof(tag));
for(int i=1;i<=q1;i++)
{
scanf("%d%d",&x,&y);
if(x==1)
{
if(q.size()<k)
{
q.push(a[y]);
tag[y]=1;
}
else
{
Node term=q.top();
if(a[y].value>term.value)
{
q.pop();
tag[term.pos]=0;
q.push(a[y]);
tag[y]=1;
}
}
}
else if(x==2)
{
if(tag[y])
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
CodeForces 639 A的更多相关文章
- Codeforces Round #639 (Div. 2)
Codeforces Round #639 (Div. 2) (这场官方搞事,唉,just solve for fun...) A找规律 给定n*m个拼图块,每个拼图块三凸一凹,问能不能拼成 n * ...
- [Codeforces 639B] Bear and Forgotten Tree 3
[题目链接] https://codeforces.com/problemset/problem/639/B [算法] 当d > n - 1或h > n - 1时 , 无解 当2h < ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- rabbitMQ之安装和配置(一)
前言 erlang是一门面向并发的编程语言,流行的消息队列rabbitMQ是基于erlang环境运行的: 下载安装erlang语言环境 源码安装 # 从官网下载,在任何目录下,使用root权限 wge ...
- Django接受ajax传过来的数组
$.ajax({ cache: false, type: "POST", url: "/userdelete/", traditional:true, //加上 ...
- 设置open_cursors参数
1.进入终端,输入命令:sqlplus /nolog 2.输入命令:conn /as sysdba 3.输入命令:alter system set open_cursors=1000 scope=me ...
- lua工具库penlight--02表和数组
类Python的List lua的优美之处在于把数组和关联数组都用table实现了(Python中叫list和dict,C++中叫vector和map). 一般我们把数字索引的table叫做list. ...
- 本机添加多个git仓库账号
我们可能会需要在一台电脑上以不同的github账户去使用git,这时就需要去解决如何管理本机上的多个ssh key的问题了. 生成新ssh key 如果我们电脑上已经存在了一个ssh key,那么我们 ...
- 24SpringMvc中的重定向和转发-解释return "redirect:/cargo/contractproduct/tocreate.action";
我在做JK项目时发现:我们在增加一个货物时.会先根据提交的Action()进入到一个新增页面 //跳转到新增的页面 @RequestMapping("/cargo/contractprodu ...
- 一般来说,主方法main()结束的时候线程结束
suspend()是将一个运行时状态进入阻塞状态(注意不释放锁标记).恢复状态的时候用resume().Stop()指释放全部. 这几个方法上都有Deprecated标志,说明这个方法不推荐使用. 一 ...
- HTML5+Canvas+jQuery调用手机拍照功能实现图片上传(二)
上一篇仅仅讲到前台操作,这篇专门涉及到Java后台处理.前台通过Ajax提交将Base64编码过的图片数据信息传到Java后台,然后Java这边进行接收处理.通过对图片数据信息进行Base64解码,之 ...
- PyQt的QString 和 QStringList
在Qt的C++实现中的QString 和 QStringList 在Python的实现中等效替换为 "str1" 和 ["str1","str2&qu ...
- QTreeWidget 获取被双击的子项的层次路径
from PyQt5.QtWidgets import (QApplication, QWidget, QHBoxLayout, QTreeWidget, QTreeWidgetItem, QGrou ...