zoukankan      html  css  js  c++  java
  • 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
    ");
                else
                    printf("NO
    ");
            }
    
        }
        return 0;
    }
    
  • 相关阅读:
    Oracle 11g 在本机上安装PLSQL DEveloper
    Oracle 11g 启动与关闭服务的脚本
    Oracle 11g 安装过程图解
    linux下vi命令大全
    accuracy、precision、recall、true positives, true negatives, false positives 和 false negatives
    // 40、用1、2、2、3、4、5这六个数字,写一个main函数,打印出所有不同的排列, // 如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连.
    阿里巴巴第二道(研发类) 笔试题1,原题大致描述有一大批数据,百万级别的。数据项内容是:用户ID、科
    621. Task Scheduler
    625. Minimum Factorization
    623. Add One Row to Tree
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228714.html
Copyright © 2011-2022 走看看