2 solutions
-
0
map
#include <bits/stdc++.h> using namespace std; #define accelerate ios::sync_with_stdio(false),cin.tie(0); #define int long long #define PII pair<int,int> #define INF 0x3f3f3f3f #define ufor(i,st,en) for(int i=st;i<=en;i++) #define dfor(i,en,st) for(int i=en;i>=st;i--) const int N=2e5+10; unordered_map<int,int>ff; struct node{ int x,y; bool operator <(const node &xx){ return y<xx.y; } }a[N]; signed main(){ int n,m,x; accelerate; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i].x; a[i].y=i; ff[a[i].x]=i; } vector<node>v; for(int j=1;j<=m;j++){ cin>>x; if(ff[x]) v.push_back(node{a[ff[x]]}); } sort(v.begin(),v.end()); for(auto i:v) cout<<i.x<<" "; }
Information
- ID
- 6675
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 119
- Accepted
- 28
- Uploaded By