zoukankan      html  css  js  c++  java
  • 【Codeforces 639A】Bear and Displayed Friends

    【链接】 我是链接,点我呀:)
    【题意】

    【题解】

    时刻维护一下前K大的数字就好。 因为k<=6 然后数字不会减少只会增加。 因此只要维护一个大小为k的数组就ok. 保证这个数组是有序的。 写个插入排序(或者sort也可以 然后询问的话就循环k次遍历就ok

    【代码】

    #include <bits/stdc++.h>
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define LL long long
    using namespace std;
    
    const int N = 15e4;
    
    int n,k,q;
    int temp[10],a[N+10],cnt;
    
    int main()
    {
        //freopen("D:\rush.txt","r",stdin);
        scanf("%d%d%d",&n,&k,&q);
        rep1(i,1,n) scanf("%d",&a[i]);
        rep1(i,1,q){
            int ope,id;
            scanf("%d%d",&ope,&id);
            if (ope==1){
                int idx = -1;
                rep2(j,k,1)
                    if (a[id]>temp[j])
                        idx = j;
                if (idx==-1) continue;
                rep2(j,k,idx+1) temp[j] = temp[j-1];
                temp[idx] = a[id];
    
            }else{
                bool fi = false;
                rep1(j,1,k)
                    if(a[id]==temp[j]){
                        fi = true;
                        break;
                    }
                if (fi){
                    puts("YES");
                }else{
                    puts("NO");
                }
            }
        }
        return 0;
    }
    
  • 相关阅读:
    腾讯2面
    腾讯1面
    快手2面
    快手1面
    formData+ajax文件上传
    nginx限流&健康检查
    jvm crash分析
    Spring Cloud Gateway整合Eureka
    k8s-应用部署
    dockerfile-maven plugin自动镜像制作并发布
  • 原文地址:https://www.cnblogs.com/AWCXV/p/9744909.html
Copyright © 2011-2022 走看看