SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <iostream> | |
| 2 | #include <vector> | |
| 3 | ||
| 4 | using namespace std; | |
| 5 | ||
| 6 | int main() {
| |
| 7 | int n; | |
| 8 | cin >> n; | |
| 9 | int m; | |
| 10 | cin >> m; | |
| 11 | vector <int> a; | |
| 12 | for (int i = 0; i < n; i++) {
| |
| 13 | int z; | |
| 14 | cin >> z; | |
| 15 | a.push_back(z); | |
| 16 | } | |
| 17 | - | int low = 0; |
| 17 | + | for (int i = 0; i < m; i++) {
|
| 18 | - | int high = a.size() - 1; |
| 18 | + | int x; |
| 19 | - | while (high - low > 0) {
|
| 19 | + | cin >> x; |
| 20 | - | int mid = (low + high) / 2; |
| 20 | + | int l = 0; |
| 21 | - | if (a[mid] > m) {
|
| 21 | + | int r = a.size(); |
| 22 | - | low = mid; |
| 22 | + | while (r - l > 1) {
|
| 23 | - | }else {
|
| 23 | + | int m = (l + r) / 2; |
| 24 | - | high = mid; |
| 24 | + | if (x < a[m]) {
|
| 25 | - | } |
| 25 | + | l = m; |
| 26 | }else {
| |
| 27 | - | cout << high; |
| 27 | + | r = m; |
| 28 | } | |
| 29 | } | |
| 30 | if (a[r] ! = x) {
| |
| 31 | cout << 0; | |
| 32 | } else{
| |
| 33 | cout << r; | |
| 34 | } | |
| 35 | } | |
| 36 | return 0; | |
| 37 | } |