Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- vector<int> vect(100000);
- int main()
- {
- int a, b, z;
- cin >> a;
- for(int i = 0; i< a; i++) cin >> vect[i];
- sort(vect.begin(), vect.begin() + a);
- cin >> b;
- for (int i = 0; i< b; i++) {
- int l = -1, r = a, l1 = -1, r1 = a;
- cin >> z;
- while (r - l > 1) {
- int x = (r + l) / 2;
- if (vect[x] >= z)
- r = x;
- else
- l = x;
- }
- while (r1 - l1 > 1) {
- int x = (r1 + l1) / 2;
- if (vect[x] > z)
- r1 = x;
- else
- l1 = x;
- }
- //cout << r << ' ' << r1 << endl;
- if (r < a && vect[r] == z) {
- cout << l1 - r+ 1;
- }
- else {
- cout << 0;
- }
- cout << ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement