solution.cpp 1.3 KB
Newer Older
CSDN问答's avatar
CSDN问答 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#include <bits/stdc++.h>

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<int, int>;


void solve() {
	int m, n;
	cin >> m >> n;
	vector<int> h(n);
	vector<int> p(n);
	vector<int> 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<int> 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();
	}
}