Codeforces Round 918 (Div. 4) 1915F. Greetings Solution




 

Problem Link :   https://codeforces.com/contest/1915/problem/F

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. using ll = long long ;
  5. #include<ext/pb_ds/assoc_container.hpp>
  6. #include<ext/pb_ds/tree_policy.hpp>
  7. using namespace __gnu_pbds;
  8. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  9. int32_t main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. int t ;
  13. cin >> t ;
  14. while(t--){
  15. int n ; cin >> n ;
  16. vector<pair<int,int>>v;
  17. pbds s ;
  18. int x , y ;
  19. for ( int i = 0 ; i < n; i++){
  20. cin >> x >> y ;
  21. s.insert(y) ;
  22. v.push_back({x,y}) ;
  23. }
  24. sort(v.begin(),v.end()) ;
  25. long long ans = 0 ;
  26. for(auto u : v){
  27. int x = u.second;
  28. int y = s.order_of_key(x);
  29. ans += y;
  30. s.erase(x);
  31. }
  32. cout << ans << '\n';
  33. }
  34. return 0 ;
  35. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.