Codeforces Round 918 (Div. 4) 1915F. Greetings Solution
Problem Link : https://codeforces.com/contest/1915/problem/F
Solution in C++:
- /// Author : AH_Tonmoy
- #include<bits/stdc++.h>
- using namespace std;
- using ll = long long ;
- #include<ext/pb_ds/assoc_container.hpp>
- #include<ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t ;
- cin >> t ;
- while(t--){
- int n ; cin >> n ;
- vector<pair<int,int>>v;
- pbds s ;
- int x , y ;
- for ( int i = 0 ; i < n; i++){
- cin >> x >> y ;
- s.insert(y) ;
- v.push_back({x,y}) ;
- }
- sort(v.begin(),v.end()) ;
- long long ans = 0 ;
- for(auto u : v){
- int x = u.second;
- int y = s.order_of_key(x);
- ans += y;
- s.erase(x);
- }
- cout << ans << '\n';
- }
- return 0 ;
- }
No comments