隊列Q - 牛客
阿新 • • 發佈:2018-07-07
nbsp == ace bubuko urn col turn printf use
記錄我的魚唇時間到了。開兩個數組一個記錄 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 #definerson 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; }
隊列Q - 牛客