Advertisement
Galebickosikasa

Untitled

May 30th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <map>
  5. #include <string>
  6. #include <vector>
  7. #include <set>
  8.  
  9. using namespace std;
  10.  
  11.  
  12.  
  13. int main() {
  14. unordered_map <int, set <int>> kek;
  15.  
  16. int query_count;
  17. cin >> query_count;
  18.  
  19. for (int query_id = 0; query_id < query_count; ++query_id) {
  20. string query_type;
  21. cin >> query_type;
  22. int start, finish;
  23. cin >> start >> finish;
  24. if (query_type == "ADD") {
  25. kek[start].insert (finish);
  26. kek[finish].insert (start);
  27. } else if (query_type == "GO") {
  28. int mn = abs (start - finish);
  29. if (kek.count (start)) {
  30. auto it = kek[start].lower_bound(finish);
  31. if (it != kek[start].end()) mn = min(mn, abs(*it - finish));
  32. if (it != kek[start].begin()) {
  33. --it;
  34. mn = min(mn, abs(*it - finish));
  35. }
  36. }
  37. cout << mn << '\n';
  38. }
  39. }
  40.  
  41. return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement