• E. Two Teams(Codeforces Round #552 (Div. 3) E)(set+并查集 瞎搞)


    E. Two Teams

    time limit per test

    2 seconds

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    There are nn students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.

    The ii-th student has integer programming skill aiai. All programming skills are distinct and between 11 and nn, inclusive.

    Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and kk closest students to the left of him and kk closest students to the right of him (if there are less than kk students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).

    Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.

    Input

    The first line of the input contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the number of students and the value determining the range of chosen students during each move, respectively.

    The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n), where aiai is the programming skill of the ii-th student. It is guaranteed that all programming skills are distinct.

    Output

    Print a string of nn characters; ii-th character should be 1 if ii-th student joins the first team, or 2otherwise.

    Examples

    input

    Copy

    5 2
    2 4 5 3 1
    

    output

    Copy

    11111
    

    input

    Copy

    5 1
    2 1 3 5 4
    

    output

    Copy

    22111
    

    input

    Copy

    7 1
    7 2 1 3 5 4 6
    

    output

    Copy

    1121122
    

    input

    Copy

    5 1
    2 4 5 3 1
    

    output

    Copy

    21112
    

    Note

    In the first example the first coach chooses the student on a position 33, and the row becomes empty (all students join the first team).

    In the second example the first coach chooses the student on position 44, and the row becomes [2,1][2,1] (students with programming skills [3,4,5][3,4,5] join the first team). Then the second coach chooses the student on position 11, and the row becomes empty (and students with programming skills [1,2][1,2] join the second team).

    In the third example the first coach chooses the student on position 11, and the row becomes [1,3,5,4,6][1,3,5,4,6] (students with programming skills [2,7][2,7] join the first team). Then the second coach chooses the student on position 55, and the row becomes [1,3,5][1,3,5] (students with programming skills [4,6][4,6] join the second team). Then the first coach chooses the student on position 33, and the row becomes [1][1] (students with programming skills [3,5][3,5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 11 joins the second team).

    In the fourth example the first coach chooses the student on position 33, and the row becomes [2,1][2,1] (students with programming skills [3,4,5][3,4,5] join the first team). Then the second coach chooses the student on position 11, and the row becomes empty (and students with programming skills [1,2][1,2] join the second team).

    昨晚水题切的太慢 

    导致最后不到半小时来 实现本题

    自己想了一个办法用set代替线段树 有并查集 来完成 删除 操作

    后来比赛技术后 看到群里的巨巨说 双向链表?

    好吧想了想还是双向链表来实现此题比较简单

    还看到有的巨巨说用数组计数 然后跳着遍历?
    反正 比赛时没写出来  还有就是代码实现先多思考一下 所谓磨刀不误砍柴工 不然想错了模拟方法 会多走弯路啊

    最后就是补题代码

    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <algorithm>
    #include <iostream>
    #include <set>
    using namespace std;
    int a[200005];
    int rfather[200005];
    int lfather[200005];
    int mp[200005];
    int ans[200005];
    int rfin(int x)//向右移动到右边界 右边第一个未被选择的
    {
        if(rfather[x]==x) return x;
        return rfather[x]=rfin(rfather[x]);
    }
    int lfin(int x)//向左移动到左边界 左边第一个未被选择的
    {
        if(lfather[x]==x) return x;
        return lfather[x]=lfin(lfather[x]);
    }
    set<int,greater<int> > st;
    int main()
    {
        int n,k;
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            st.insert(a[i]);
            mp[a[i]]=i;
        }
        for(int i=0;i<=1+n;i++)
        {
            rfather[i]=i;
            lfather[i]=i;
        }
        int cnt=0;//已经完成的个数
        int x=0;//对x取余来 实现记录哪一队
        while(cnt<=n)
        {
            x++;
            int tmp;
            int pos;
            tmp=*st.begin();
            pos=mp[tmp];
            int pos1=rfin(pos+1);
            int pos2=lfin(pos-1);
            //cout<<cnt<<endl;
            //cout<<pos<<" "<<tmp<<endl;cout<<"pos1"<<pos1<<endl;cout<<"pos2"<<pos2<<endl;
            cnt++;
    
            lfather[pos]=lfin(pos-1);
            rfather[pos]=rfin(pos+1);
            st.erase(tmp);
            ans[pos]=x%2;
            int cnt1=0;
            int cnt2=0;
            while(cnt1<k&&pos1<=n)
            {
    
                cnt1++;
                cnt++;
                ans[pos1]=x%2;
                st.erase(a[pos1]);//删除
                rfather[pos1]=rfin(pos1+1);//并查集合并
                lfather[pos1]=lfin(pos1-1);
                pos1=rfin(pos);
            }
            while(cnt2<k&&pos2>=1)
            {
    
                cnt2++;
                cnt++;
                ans[pos2]=x%2;
                st.erase(a[pos2]);
                lfather[pos2]=lfin(pos2-1);
                rfather[rfin(pos2)]=rfin(pos2+1);
                pos2=lfin(pos);
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(ans[i]==0) printf("2");
            else printf("%d",ans[i]);
        }
        printf("
    ");
    }
    
  • 相关阅读:
    每日总结
    SQLServer2008/2005 生成数据字典SQL语句
    python一些utils
    python快速展示图片
    面向对象编程
    Arrays类讲解 冒泡排序
    方法的定义、方法的调用及方法的重载
    .Net6 连接 redis
    Stream流的基本使用
    uniapp 页面之前通讯传值 义美
  • 原文地址:https://www.cnblogs.com/caowenbo/p/11852286.html
Copyright © 2020-2023  润新知