也会有发光的一天吖


私信TA

用户名:wzi

访问量:7854

签 名:

我怎么能这么笨啊,脑袋长的干嘛的?

等  级
排  名 108
经  验 7814
参赛次数 0
文章发表 37
年  龄 88
在职情况 学生
学  校 蓝翔技校
专  业

  自我简介:

1.素质教育漏网之鱼 2.晚睡协会常任理事3.情侣辩论赛冠军 4. 国家级抬杠运动员6.中国驰名窝里横 7.家里蹲大学博士

解题思路:

注意事项:

参考代码:

#include <iostream>

#include <cstring>

#include <algorithm>

#include <cmath>


using namespace std;


const int N = 100005;

pair<int,int> s[N];

int ret[N];

int n,m;


int main(){

    cin>>n>>m;

    int top=0;

    int k=n;

    for(int i=0;i<m;i++){

        int p,q;

        cin>>p>>q;

        //0 是 1->q降序排列

        if(!p){

            while(top&&s[top].first==0)

                q=max(q,s[top--].second);

            while(top>=2&&s[top-1].second<=q)

                top-=2;

            s[++top]={0,q};

        }

        else if(top){

            while(top&&s[top].first==1)

                q=min(q,s[top--].second);

            while(top>=2&&s[top-1].second>=q)

                top-=2;

            s[++top]={1,q};

        }

    }

    int l=1,r=n;

    for(int i=1;i<=top;i++){

        if(s[i].first==0)

            while(l<=r&&r>s[i].second)

                ret[r--]=k--;

        else

            while(l<=r&&l<s[i].second)

                ret[l++]=k--;

        if(l>r)

            break;

    }

    if(top%2)

        while(l<=r)

            ret[l++]=k--;

    else

        while(l<=r)

            ret[r--]=k--;

    for(int i=1;i<=n;i++)

        cout<<ret[i]<<" ";

    return 0;

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区