Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #pragma GCC target ("sse4")
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<string,int> psi;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef vector<ll> vll;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<string>> vvs;
- typedef vector<vector<ll>> vvll;
- #define FOR(i, a, b) for (ll i=a; i<=(b); i++)
- #define FORd(i,b,a) for (ll i =b; i >= a; i--)
- #define sz(x) (int)(x).size()
- #define mp make_pair
- #define pb push_back
- #define f first
- #define s second
- #define ins insert
- const int MOD = 1000000007;
- //type functions here
- ll BS1(vi v,ll k)
- {
- ll low=0,high=sz(v)-1,p1=0;
- ll mid;
- while(low<=high)
- {
- mid=(low+high)/2;
- if(v[mid]<k)
- low=mid+1;
- else if(v[mid]>k)
- high=mid-1;
- else
- { p1=mid;
- high=mid-1;
- }
- }
- return p1;
- }
- ll BS2(vi v,ll k)
- {
- ll low=0,high=sz(v)-1,p2=-1;//observe p2 value
- ll mid;
- while(low<=high)
- {
- mid=(low+high)/2;
- if(v[mid]<k)
- low=mid+1;
- else if(v[mid]>k)
- high=mid-1;
- else
- { p2=mid;
- low=mid+1;
- }
- }
- return p2;
- }
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- int size,qsize;
- cin>>size;
- vi v;
- FOR(i,1,size)
- {
- ll temp;
- cin>>temp;
- v.pb(temp);
- }
- sort(v.begin(),v.end());
- cin>>qsize;
- FOR(i,1,qsize)
- {
- ll temp;
- cin>>temp;
- ll x=temp;
- ll temp2= ((BS2(v,x))-(BS1(v,x))+1);
- cout<<temp2<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement