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. for(int i=0; i<n; i++){
  18. cin>>v[i];
  19. st.insert(v[i]);
  20. }
  21.  
  22. while (q--){
  23. int x; cin>>x;
  24.  
  25. auto tmp = st.lower_bound(x);
  26. int idx = distance(st.begin(), tmp);
  27.  
  28.  
  29. if(tmp==st.end()){
  30. cout<< n << " 0" <<endl;
  31. }
  32.  
  33. //int idx=tmp-st.begin();
  34.  
  35. else if(*tmp==x) cout<< idx << " "<<st.size()-idx-1<<endl;
  36. else cout<<idx << " "<<st.size()-idx<<endl;
  37.  
  38.  
  39.  
  40.  
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. }
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