Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- void ez()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- bool comp(ll &a, ll &b)
- {
- return a > b;
- }
- void solve()
- {
- ll n, m, ans = 0;
- cin >> n >> m;
- vector<ll> a(n), b(m), h;
- for (auto &i : a)
- cin >> i;
- for (auto &i : b)
- cin >> i;
- ll f = 0, l = 0;
- while (f < n and l < m)
- {
- ll cnt = 0;
- while (l < m and b[l] < a[f])
- {
- l++;
- }
- while (a[f] == b[l])
- {
- cnt++;
- l++;
- }
- do
- {
- f++;
- ans += cnt;
- } while (a[f] == a[f - 1]);
- }
- cout << ans << endl;
- }
- int main()
- {
- ez();
- int t = 1;
- // cin >> t;
- while (t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment