Ledger Nano X - The secure hardware wallet
SHARE
TWEET

smmr-085

lLab__ Apr 7th, 2020 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef pair<int,int> pii;
  4.  
  5. int bs(vector<pii> &arr,int data,int l,int r){
  6.     int m = (l+r)/2;
  7.     int x = arr[m].first;
  8.  
  9.     if(x == data){
  10.         return arr[m].second;
  11.     }
  12.  
  13.     if(l >= r){
  14.         return -1;
  15.     }else if(x < data){ // search in right
  16.         return bs(arr,data,m+1,r);
  17.     }else{ // search in left
  18.         return bs(arr,data,l,m);
  19.     }
  20. }
  21.  
  22. int main(){
  23.     int n,m;
  24.     priority_queue<pii,vector<pii>,greater<pii>> pq;
  25.  
  26.     scanf("%d",&n);
  27.  
  28.     for(int i=1;i<=n;++i){
  29.         int a;
  30.  
  31.         scanf("%d",&a);
  32.  
  33.         pq.push({a,i});
  34.  
  35.     }
  36.  
  37.     int r = 0;
  38.  
  39.     vector<pii> arr(n+1,{0,0});
  40.  
  41.     while(!pq.empty()){
  42.         int a = pq.top().first;
  43.         int b = pq.top().second;
  44.  
  45.         pq.pop();
  46.  
  47.         if(r != 0 && arr[r-1].first == a){
  48.             arr[r-1].second = min(arr[r-1].second , b);
  49.         }else{
  50.             arr[r].first = a;
  51.             arr[r].second = b;
  52.  
  53.             r++;
  54.         }
  55.  
  56.     }
  57.  
  58.     scanf("%d",&m);
  59.  
  60.     for(int i=0;i<m;++i){
  61.         int a;
  62.         scanf("%d",&a);
  63.  
  64.         int poss = bs(arr,a,0,r-1);
  65.         if(poss == -1){
  66.             printf("Not found\n");
  67.         }else{
  68.             printf("%d\n",poss);
  69.         }
  70.     }
  71.  
  72.     return 0;
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top