队列Q - 牛客

记录我的鱼唇时间到了。开两个数组一个记录 frist,另一个记录 last,然后输出。。。。。果断挂了,因为同一个数可以操作多次,所以还需要记录每个数的位置!!!

#include<bits/stdc++.h>
#define ll long long
#define P pair<int, int>
#define PP pair<int,pair<int, int>>
#define pb push_back
#define pp pop_back
#define lson root << 1
#define INF (int)2e9 + 7
#define rson root << 1 | 1
#define LINF (unsigned long long int)1e18
#define mem(arry, in) memset(arry, in, sizeof(arry))
using namespace std;

const int maxn = 200005;

int n, q;
int a[maxn], F[maxn], L[maxn], pos[maxn], use[maxn];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    cin >> q;

    int x, cnt = 0, cnt1 = 200005;
    while(q--) {
        string tp;
        cin >> tp >> x;
        pos[x] = 0;
        use[x] = 1;
        if(tp[0] == 'F') {
            F[--cnt1] = x;
            pos[x] = cnt1;
        }
        else {
            L[++cnt] = x;
            pos[x] = cnt;
        }
    }

    vector<int> ans;
    for(int i = cnt1; i < 200005; i++) if(i == pos[F[i]]) ans.pb(F[i]);
    for(int i = 1; i <= n; i++) if(!use[a[i]]) ans.pb(a[i]);
    for(int i = 1; i <= cnt; i++) if(i == pos[L[i]]) ans.pb(L[i]);

    int m = (int)ans.size();
    for(int i = 0; i < m; i++) printf("%d%c", ans[i], i + 1 == m ? '\n' : ' ');
    return 0;
}

 

posted @ 2018-07-07 20:20  天之道,利而不害  阅读(187)  评论(0编辑  收藏  举报