Dhiraj-01

Number of Equal (CF)

Feb 8th, 2021 (edited)
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. // https://codeforces.com/edu/course/2/lesson/9/1/practice/contest/307092/problem/C
  2.  
  3. void solve(int &tc)
  4. {
  5.     ll n, m;
  6.     cin >> n >> m;
  7.  
  8.     vector<ll> a(n), b(m);
  9.     cin >> a >> b;
  10.  
  11.     ll i = 0, j = 0;
  12.     ll ans = 0;
  13.     while(i < a.size() and j < b.size())
  14.     {
  15.         ll cnt1 = 0, cnt2 = 0;
  16.         ll x = a[i];
  17.         while(j < b.size() and b[j] < x) {
  18.             j++;
  19.         }
  20.         while(i < a.size() and a[i] == x) {
  21.             i++;
  22.             cnt1++;
  23.         }
  24.         while(j < b.size() and b[j] == x) {
  25.             j++;
  26.             cnt2++;
  27.         }
  28.         ans += cnt1 * cnt2;
  29.     }
  30.     cout << ans << endl;
  31. }
Add Comment
Please, Sign In to add comment