#include <bits/stdc++.h>
using namespace std;
#define lol 1000000007
#define fol 1000000000
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int expo(int n, int k, int mod)
{
if (k == 0)
return 1 % mod;
int u = expo(n, k / 2, mod);
u = (u * u) % mod;
if (k % 2 != 0)
u = (u * n) % mod;
return u;
}
int sqrt(int n)
{
if (n < 0)
return -1;
int L = 0, R = 2000000000;
while (L < R)
{
int mid = (L + R) / 2;
if (mid * mid >= n)
R = mid;
else
L = mid + 1;
}
return L;
}
int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : int(n) * factorial(n - 1);
}
const int N = 50001;
vvi adj(N);
vi visited(N);
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/*freopen("herding.in","r",stdin);
freopen("herding.out","w",stdout); */
int f = 1;
cin >> f;
while (f--)
{
int n;
cin >> n;
ordered_set s;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i].first;
cin >> v[i].second;
s.insert(v[i].second);
}
sort(all(v));
long long ans = 0;
for (int i = 0; i < n; i++)
{
ans += s.order_of_key(v[i].second);
// ans -= s.order_of_key(v[i].first);
s.erase(v[i].second);
}
cout << ans << "\n";
}
}
892A - Greed | 32A - Reconnaissance |
1236D - Alice and the Doll | 1207B - Square Filling |
1676D - X-Sum | 1679A - AvtoBus |
1549A - Gregor and Cryptography | 918C - The Monster |
4B - Before an Exam | 545B - Equidistant String |
1244C - The Football Season | 1696B - NIT Destroys the Universe |
1674A - Number Transformation | 1244E - Minimizing Difference |
1688A - Cirno's Perfect Bitmasks Classroom | 219A - k-String |
952A - Quirky Quantifiers | 451B - Sort the Array |
1505H - L BREAK into program | 171E - MYSTERIOUS LANGUAGE |
630D - Hexagons | 1690D - Black and White Stripe |
1688D - The Enchanted Forest | 1674C - Infinite Replacement |
712A - Memory and Crow | 1676C - Most Similar Words |
1681A - Game with Cards | 151C - Win or Freeze |
1585A - Life of a Flower | 1662A - Organizing SWERC |