fork download
  1. #include <bits/stdc++.h>
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #define endl "\n"
  4. #define ll long long
  5. #define all(x) x.begin(),x.end()
  6. #define Sherlock_Holmes ios_base::sync_with_stdio(false); cin.tie(nullptr);
  7. #define int long long
  8. using namespace std;
  9.  
  10. signed main()
  11. {
  12. Sherlock_Holmes
  13.  
  14. int n,q; cin>>n>>q;
  15. vector<ll>v(n);
  16. set<ll>st;
  17.  
  18. for(int i=0; i<n; i++){
  19. cin>>v[i];
  20. st.insert(v[i]);
  21. }
  22.  
  23. vector<ll> unique_elements;
  24.  
  25. auto it=st.begin();
  26. while(it!=st.end()){
  27. unique_elements.push_back(*it);
  28. it++;
  29. }
  30.  
  31.  
  32.  
  33. while (q--){
  34. int x; cin>>x;
  35.  
  36. auto tmp = lower_bound(unique_elements.begin(), unique_elements.end(), x);
  37.  
  38. int idx = tmp-unique_elements.begin();
  39.  
  40.  
  41. if(tmp==unique_elements.end()){
  42. cout<< unique_elements.size() << " 0" <<endl;
  43. }
  44.  
  45. else if(*tmp==x) cout<< idx << " "<<unique_elements.size()-idx-1<<endl;
  46. else cout<<idx << " "<<unique_elements.size()-idx<<endl;
  47.  
  48.  
  49.  
  50.  
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57. }
Runtime error #stdin #stdout #stderr 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc