Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<ll,ll>pll;
- typedef pair<ll,pair<ll,ll> >pk;
- #define sf(a) scanf("%d",&a)
- #define pf(a) printf("%d\n",a)
- #define F first
- #define S second
- #define minheap int,vector<int>,greater<int>
- #define mp make_pair
- #define pb push_back
- #define pp pop_back
- #define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
- #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
- const int Max = 2e6 + 10;
- const int Mod = 1e9 + 7;
- bool compare(const pair<int,int> &a,
- const pair<int,int> &b)
- {
- return (a.second > b.second);
- }
- ll b_search(vector<pll>ara,int low,int high,int k)
- {
- while(low<=high)
- {
- int mid=(low+high)/2;
- if(ara[mid].F==k) return mid;
- if(k>ara[mid].F) low=mid+1;
- else high=mid-1;
- }
- return -1;
- }
- int main()
- {
- fastread();
- vector<pll>v;
- int i,n,k;
- cin>>n;
- for(i=0; i<n; i++)
- {
- cin>>k;
- v.pb(mp(k,i));
- }
- sort(v.begin(),v.end());
- cin>>k;
- int sum=b_search(v,0,n-1,k);
- if(sum==-1)cout<<"Not found\n";
- else cout<<v[sum].S<<endl;
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement