codeforces - 799B
Posted NWU_ACM
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces - 799B相关的知识,希望对你有一定的参考价值。
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 }
以上是关于codeforces - 799B的主要内容,如果未能解决你的问题,请参考以下文章
[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段
Codeforces 86C Genetic engineering(AC自动机+DP)