Codeforces Round #344 (Div. 2) C. Report 水题

Posted __560

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #344 (Div. 2) C. Report 水题相关的知识,希望对你有一定的参考价值。

技术分享
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define MS0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=a;i>=b;i--)
#define RI(x) scanf("%d",&x)
#define RII(x,y) scanf("%d%d",&x,&y)
#define RIII(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RS(s) scanf("%s",s)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lowbit(x) x&-x
#define key_val ch[ch[rt][1]][0]

using namespace std;

typedef long long ll;
const int maxn=2000100;
const int INF=1e9+10;
const double EPS=1e-10;
const double Pi=acos(-1.0);

int n,m;
int a[maxn];
struct Query
{
    int op,r;
};Query q[maxn];
multiset<int> s;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
    #endif
    while(cin>>n>>m){
        REP(i,1,n) RI(a[i]);
        int ops=1,rs=n+1;
        REP(i,1,m) scanf("%d%d",&q[i].op,&q[i].r);
        stack<Query> stk;
        int qn=0;
        REP(i,1,m){
            while(!stk.empty()&&stk.top().r<=q[i].r) stk.pop();
            stk.push(q[i]);
        }
        qn=(int)stk.size();
        for(int i=qn;i>=1;i--) q[i]=stk.top(),stk.pop();
        s.clear();
        REP(i,1,q[1].r) s.insert(a[i]);
        multiset<int>::iterator it,it2;
        q[qn+1].r=0;q[qn+1].op=1;
        REP(i,1,qn){
            if(q[i].op==1){
                for(int d=q[i].r;d>q[i+1].r;d--){
                    it=s.end();--it;
                    a[d]=*it;
                    s.erase(it);
                }
            }
            else{
                for(int d=q[i].r;d>q[i+1].r;d--){
                    it=s.begin();
                    a[d]=*it;
                    s.erase(it);
                }
            }
        }
        REP(i,1,n) printf("%d ",a[i]);puts("");
    }
    return 0;
}
View Code

 

以上是关于Codeforces Round #344 (Div. 2) C. Report 水题的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #344 (Div. 2)(按位或运算)

Codeforces Round #344 (Div. 2) C. Report 水题

Codeforces Round #344 (Div. 2) C. Report

Codeforces Round #344 (Div. 2) 631 C. Report (单调栈)

Codeforces Round #344 (Div. 2)C. Report

Codeforces Round #344 (Div. 2) E. Product Sum 二分斜率优化DP