fork download
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp> // Common file
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #include<math.h>
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. typedef tree<long long int, null_type, less<long long int>, rb_tree_tag,
  9. tree_order_statistics_node_update>
  10. new_data_set;
  11.  
  12. int main() {
  13. long long int Q, K;
  14. cin >> Q >> K;
  15. new_data_set s;
  16.  
  17. while (Q--) {
  18. int query;
  19. cin >> query;
  20. vector <long long int> v;
  21. long long int x, y;
  22. if (query == 1) {
  23.  
  24. cin >> x >> y;
  25. v.push_back(x);
  26. v.push_back(y);
  27. int distance = x * x + y * y;
  28. s.insert(distance);
  29. } else {
  30. cout << *s.find_by_order(2) << endl;
  31. }
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 4412KB
stdin
9 3
1 10 10
1 9 9
1 -8 -8
2
1 7 7
2
1 6 6 
1 5 5
2
stdout
200
162
98