Advertisement
cosenza987

Untitled

May 16th, 2022
1,029
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3.  
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6.  
  7. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(0);
  12.     int t;
  13.     cin >> t;
  14.     while(t--) {
  15.         int n;
  16.         cin >> n;
  17.         vector<string> v(n);
  18.         indexed_set x;
  19.         for(int i = 0; i < n; i++) {
  20.             cin >> v[i];
  21.         }
  22.         int cur = 1;
  23.         map<string, int> id;
  24.         for(int i = 0; i < n; i++) {
  25.             string s;
  26.             cin >> s;
  27.             id[s] = cur++;
  28.         }
  29.         int ans = 0;
  30.         for(int i = 0; i < n; i++) {
  31.             ans += x.size() - x.order_of_key(id[v[i]]);
  32.             x.insert(id[v[i]]);
  33.         }
  34.         cout << ans << "\n";
  35.     }
  36.     return 0;
  37. }
Advertisement
RAW Paste Data Copied
Advertisement