6 条题解
-
0
#include <bits/stdc++.h> using namespace std; #define endl "\n" typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, q; cin >> n; cin >> q; vector<ll> q_arr(q); vector<ll> a(n); ll index_begin, index_end; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < q; ++i) { cin >> q_arr[i]; } for (ll q_i : q_arr) { auto it_l = lower_bound(a.begin(), a.end(), q_i); if (it_l == a.end() or (*it_l != q_i)) { printf("-1 -1\n"); } else { index_begin = distance(a.begin(), it_l); index_end = distance(a.begin(), upper_bound(it_l, a.end(), q_i))-1; printf("%lld %lld\n", index_begin, index_end); } } return 0; }
信息
- ID
- 88
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 655
- 已通过
- 149
- 上传者