Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://codeforces.com/edu/course/2/lesson/9/1/practice/contest/307092/problem/C
- void solve(int &tc)
- {
- ll n, m;
- cin >> n >> m;
- vector<ll> a(n), b(m);
- cin >> a >> b;
- ll i = 0, j = 0;
- ll ans = 0;
- while(i < a.size() and j < b.size())
- {
- ll cnt1 = 0, cnt2 = 0;
- ll x = a[i];
- while(j < b.size() and b[j] < x) {
- j++;
- }
- while(i < a.size() and a[i] == x) {
- i++;
- cnt1++;
- }
- while(j < b.size() and b[j] == x) {
- j++;
- cnt2++;
- }
- ans += cnt1 * cnt2;
- }
- cout << ans << endl;
- }
Add Comment
Please, Sign In to add comment