1 条题解
-
0
使用
lower_bound
即可#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int n, m, a[MAXN], q; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; sort (a + 1, a + n + 1); for (int i = 1, x; i <= m; i++) { cin >> q, x = lower_bound(a + 1, a + n + 1, q) - a; while (a[x] == q) x++; cout << ((a[x - 1] == q) ? n - x + 2 : -1) << " "; } return 0; }
- 1
信息
- ID
- 626
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- (无)
- 递交数
- 149
- 已通过
- 76
- 上传者