Advertisement
sasa2742002

Untitled

Dec 20th, 2022
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. #include <ext/pb_ds/tree_policy.hpp>
  5. using namespace __gnu_pbds;
  6. #define T     \
  7.   ll rrr;     \
  8.   cin >> rrr; \
  9.   for (ll w1 = 0; w1 < rrr; w1++)
  10. #define cin(vec, a) for (ll i = 0; i < a && cin >> vec[i]; i++)
  11. #define cout(vec, a) for (ll i = 0; i < a && cout << vec[i] << " "; i++)
  12. #define MOD 1000000007
  13. #define PI 3.14159265
  14. #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))
  15. #define all(v) v.begin(), v.end()
  16. #define rall(v) v.rbegin(), v.rend()
  17. #include <iostream>
  18. #define INF 1e9
  19. #define mod 1000000007
  20. #include <string>
  21. #define el '\n'
  22. #define sp ' '
  23. #define loop(n) for (int i = 0; i < n; i++)
  24. typedef long long ll;
  25. #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
  26. #define multi_ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
  27.  
  28. void sasa()
  29. {
  30.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  31. #ifndef ONLINE_JUDGE
  32.   freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  33. #endif
  34. }
  35.  
  36. struct s
  37. {
  38.   bool operator()(pair<ll,ll> a,pair<ll,ll> b)
  39.   {
  40.     if(a.first == b.first)
  41.       return a.second < b.second;
  42.     return a.first < b.first;
  43.   }
  44. };
  45. void solve()
  46. {
  47.     ll n,m;
  48.     cin >> n >> m ;
  49.     vector<pair<ll,ll>> a(n),b(m);
  50.     for(int i = 0 ; i < n ; i++)
  51.     {
  52.       int l,k;
  53.       cin >> l >> k;
  54.       a[i] = {k,l};
  55.     }
  56.     for(int i = 0 ; i < m ; i++)
  57.     {
  58.       int l,k;
  59.       cin >> l >> k;
  60.       b[i] = {k,l};
  61.     }
  62.     sort(all(a),s());
  63.     sort(all(b),s());
  64.     int i=0,j=0;
  65.     int res1=0,res2=0;
  66.     while(i < n && j < m)
  67.     {
  68.         if(a[i].first == b[j].first && a[i].second == b[j].second)
  69.         {
  70.             i++;
  71.             j++;
  72.             res1++;
  73.             res2++;
  74.         }
  75.         else if (a[i].first == b[j].first)
  76.         {
  77.             i++;
  78.             j++;
  79.             res1++;
  80.         }
  81.         else if (a[i].first < b[j].first)
  82.         {
  83.             i++;
  84.         }
  85.         else
  86.         {
  87.             j++;
  88.         }
  89.        
  90.     }
  91.     cout << res1 << " " << res2 << el;
  92. }
  93.  
  94. int main()
  95. {
  96.   sasa();
  97.  
  98.   ll t = 1, i = 1;
  99.   // cin >> t;
  100.   while (t--)
  101.   {
  102.     //  cout << "Case #" << i << ": ";
  103.     solve();
  104.     i++;
  105.     if (!t)
  106.       break;
  107.     cout << "\n";
  108.   }
  109.  
  110.   return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement