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 ...
随机推荐
- Android Studio 使用感受 错误解决
刚到公司不久,公司叫我用Android studio软件,曾经一直在用的是eclipse ADT.突然接触到的新名词让我有点适应只是来. 好吧,既然是公司要求,肯定有它的道理.就从网上下载了它的安装包 ...
- C#多枚举值的写法与读法
首先,定义枚举的时候必须是2,4,8,16这种2的次方的值. using System; using System.Collections.Generic; using System.Linq; us ...
- python—networkx:在一张图中画出多个子图
通过plt.subplot能够在一张图中画出多个子图 #coding: utf-8 #!/usr/bin/env python """ Draw a graph with ...
- ubuntu 16.04 安装 ITDB
其实标题本不应该是这个 之前也部署过itdb,这款软件本身不必多言,来自希腊的精品.最近因为单位需要,又要重新部署.前几年部署itdb的时候用的是ub14,但目前最新的是ub16,于是就部署呗.但在后 ...
- Win7-U盘安装出现"We were unable to copy your files. "
使用Windows 7 USB/DVD Download Tool时,提示We were unable to copy your files. Please check your USB device ...
- inline函数出现 undefined reference 错误
原因:你把inline函数的implementation放到cpp文件里肯定要报这个错误 正确的做法:把inline函数的声明和实现都放到header里,例如 // declaration: retu ...
- dp背包之01背包poj2184
http://poj.org/problem?id=2184 题意:给定两个属性,求这两个属性的和的最大值......... 思路:将第一个属性往后平移1000个单位,然后推导其动态转移方程,若是dp ...
- 针对16v554(ttyS0-15)的ttyAT0的login配置
1 ## /etc/inittab# console::sysinit:/etc/init.d/rcSconsole::respawn:/sbin/getty -L 115200 ttyAT0 vt1 ...
- 1.thinkphp 权限分析
一.权限分析 用户表 user角色表 role权限表 node think_acces role_id 用户组idnode_id 节点IDlevel 节点等级pid 父级ID THINK_ACCESS ...
- C++ 类的深拷贝和浅拷贝完美解决
//类的深拷贝和浅拷贝 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; class Poin ...