Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // { Driver Code Starts
- #include<bits/stdc++.h>
- using namespace std;
- vector<int> find(int a[], int n , int x );
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n,x;
- cin>>n>>x;
- int arr[n],i;
- for(i=0;i<n;i++)
- cin>>arr[i];
- vector<int> ans;
- ans=find(arr,n,x);
- cout<<ans[0]<<" "<<ans[1]<<endl;
- }
- return 0;
- }
- // } Driver Code Ends
- vector<int> find(int arr[], int n , int x )
- {
- // code here
- int lo = lower_bound(arr, arr + n, x) - arr;
- int up = upper_bound(arr, arr + n, x) - arr;
- vector<int> v;
- if (lo == n) {
- v.push_back(-1);
- v.push_back(-1);
- return v;
- }
- if (arr[lo] != x) {
- v.push_back(-1);
- v.push_back(-1);
- return v;
- }
- v.push_back(lo);
- v.push_back(up - 1);
- return v;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement