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

 

posted @ 2016-03-04 17:39  __560  阅读(260)  评论(0编辑  收藏  举报