NWU_ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define rep(i,a,b) for(int i = a;i <= b;++ i)
 4 #define per(i,a,b) for(int i = a;i >= b;-- i)
 5 #define mem(a,b) memset((a),(b),sizeof((a)))
 6 #define FIN freopen("in.txt","r",stdin)
 7 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
 8 #define pb push_back
 9 typedef long long LL;
10 typedef pair<int, int> PIR;
11 const int MAXN = 2e5+5;
12 
13 int n, m, x, a[MAXN], b[MAXN], p[MAXN];
14 bool vis[MAXN];
15 vector <int> ans;
16 struct Node {
17     int id, p;
18     Node (int _id, int _p)  { id = _id; p = _p; }
19     bool operator < (const Node &r) const   { return p > r.p; }
20 };
21 priority_queue <Node> vet[5];
22 
23 int main()
24 {IO;
25     //FIN;
26     cin >> n;
27     rep(i, 1, n)    cin >> p[i];
28     rep(i, 1, n)    cin >> a[i];
29     rep(i, 1, n)    cin >> b[i];
30     rep(i, 1, n) {
31         vet[a[i]].push(Node(i, p[i]));
32         vet[b[i]].push(Node(i, p[i]));
33     }
34     cin >> m;
35     rep(i, 1, m) {
36         cin >> x;
37         if(vet[x].empty())  ans.pb(-1);
38         else {
39             int ok = 0;
40             while(!vet[x].empty()) {
41                 Node h = vet[x].top(); vet[x].pop();
42                 if(!vis[h.id]) {
43                     ok = 1;
44                     ans.pb(p[h.id]);
45                     vis[h.id] = true;
46                     break;
47                 }
48             }
49             if(!ok) ans.pb(-1);
50         }
51     }
52     rep(i, 0, m-1) {
53         if(i)   cout << " ";
54         cout << ans[i];
55     }
56     cout << endl;
57     return 0;
58 }
View Code

 

posted on 2017-05-21 20:43  NWU_ACM  阅读(108)  评论(0编辑  收藏  举报