cf 一般都在晚上,这一场没做,听同学说这个题很迷,来了兴趣,就做了一下
开始想用set ,但感觉好恶心的,不易实现,细思之下想到了好的办法,算是 “贪心” 了一下
运用 queue 先进先出 结合 结构体,嗯,不错
这种顺序问题,最好寻找一种规律,想到了 会很简单;整个代码我也就敲了20分钟吧,前面思考的过程耗时间
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;
const int maxn = 200000 + 50;
int n, m;
queue<int> q1;
queue<int> q2;
queue<int> q3;
struct node {
int pr;
int f;
int x;
int y;
};
node a[maxn];
bool cmp(node a, node b) {
return a.pr < b.pr;
}
void clear_() {
while(!q1.empty()) q1.pop();
while(!q2.empty()) q2.pop();
while(!q3.empty()) q3.pop();
}
void init() {
clear_();
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d", &a[i].pr);
a[i].f = 1;
}
for(int i = 0; i < n; ++i) scanf("%d", &a[i].x);
for(int i = 0; i < n; ++i) scanf("%d", &a[i].y);
sort(a, a+n, cmp);
for(int i = 0; i < n; ++i) {
if(a[i].x == 1 || a[i].y == 1) q1.push(i);
if(a[i].x == 2 || a[i].y == 2) q2.push(i);
if(a[i].x == 3 || a[i].y == 3) q3.push(i);
}
}
void solve(){
scanf("%d", &m);
for(int i = 0; i < m; ++i) {
int ff = 0, b;
scanf("%d", &b);
if(i) cout << " ";
if(b == 1) {
while(!q1.empty()) {
int t = q1.front();
if(a[t].f) {
a[t].f = 0;
cout << a[t].pr;
ff = 1;
}
q1.pop();
if(ff) break;
}
if(!ff) cout << -1;
}
else if(b == 2) {
while(!q2.empty()) {
int t = q2.front();
if(a[t].f) {
a[t].f = 0;
cout << a[t].pr;
ff = 1;
//cout << "==" <<
}
q2.pop();
if(ff) break;
}
if(!ff) cout << -1;
}
else if(b == 3) {
while(!q3.empty()) {
int t = q3.front();
if(a[t].f) {
a[t].f = 0;
cout << a[t].pr;
ff = 1;
}
q3.pop();
if(ff) break;
}
if(!ff) cout << -1;
}
}
//cout << endl;
}
int main() {
init();
solve();
return 0;
}