#include using namespace std; #define out(x) cout << #x << '=' << x << endl #define out2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y << endl #define no cout << "No" << endl; return #define yes cout << "Yes" << endl; return #define outvec(a) for (int v : a) { cout << v << ' '; } cout << endl #define lowbit(x) (x & -x) #define gcd __gcd #define inf 0x3f3f3f3f3f3f3f3fLL #define infi 0x3f3f3f3f using ll = long long; using pii = pair; void solve() { int m, n; cin >> m >> n; vector h(n); vector p(n); vector id(n); for (int i = 0; i < n; i++) { cin >> h[i]; id[i] = i; } for (int i = 0; i < n; i++) { cin >> p[i]; } sort(id.begin(), id.end(), [&](int a, int b) -> int { return p[a] < p[b]; }); vector stk; for (int i = 0; i < n; i++) { if (stk.empty() || h[stk.back()] < h[id[i]]) { stk.push_back(id[i]); } } for (int i = 0; i < m; i++) { int a; cin >> a; int left = 0; int right = (int) stk.size() - 1; int ans = -1; while (left <= right) { int mid = left + (right - left) / 2; if (p[stk[mid]] > a) { right = mid - 1; } else { left = mid + 1; ans = p[stk[mid]]; } } cout << ans << endl; } } int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { solve(); } }