fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. int main()
  6. {
  7. int n{}, q{}, w{};
  8. std::cin >> n;
  9. std::vector<std::pair<int, int>>a;
  10. std::vector<std::pair<int, int>>b;
  11.  
  12. for (int i = 0; i < n; i++) {
  13. std::cin >> q >> w;
  14. a.push_back(std::make_pair(q, i));
  15. b.push_back(std::make_pair(w, i));
  16. }
  17. std::sort(a.begin(), a.end(), [](const std::pair<int, int>& l, const std::pair<int, int>& k) {
  18. return l.first < k.first;
  19. });
  20.  
  21. std::sort(b.begin(), b.end(), [](const std::pair<int, int>& ll, const std::pair<int, int>& kk) {
  22. return ll.first < kk.first;
  23. });
  24.  
  25. int m{};
  26. std::cin >> m;
  27. int* c = new int[m];
  28. int* d = new int[m];
  29.  
  30. for (int i = 0; i < m; i++) {
  31. std::cin >> c[i] >> d[i];
  32. }
  33.  
  34. for (int i = 0; i < m; i++) {
  35. if (a[0].first >= c[i] && b[0].first >= d[i]) {
  36. std::cout << "Remis\n";
  37. continue;
  38. }
  39.  
  40. int lewy{ 0 };
  41. int prawy{ n - 1 };
  42. int sr{ (prawy + lewy) / 2 };
  43. int poma{ 0 };
  44. int pomb{ 0 };
  45. int testta = 0;
  46. int testtb = 0;
  47.  
  48. int lewyb{ 0 };
  49. int prawyb{ n - 1 };
  50. int srb{ (prawyb + lewyb) / 2 };
  51.  
  52. while (lewy <= prawy || lewyb <= prawyb) {
  53.  
  54. if (a[lewy].first < c[i]) {
  55. testta = 1;
  56. if (a[lewy].second < a[poma].second)
  57. poma = lewy;
  58. }
  59. if (a[sr].first >= c[i]) {
  60. prawy = sr - 1;
  61. sr = (prawy + lewy) / 2;
  62. }
  63. lewy += 1;
  64.  
  65. if (b[lewyb].first < d[i]) {
  66. testtb = 1;
  67. if (b[lewyb].second < b[pomb].second)
  68. pomb = lewyb;
  69. }
  70.  
  71. if (b[srb].first >= d[i]) {
  72. prawyb = srb - 1;
  73. sr = (prawyb + lewyb) / 2;
  74. }
  75. lewyb += 1;
  76. }
  77.  
  78. if (testta == 0 && testtb == 0 || (a[poma].second == b[pomb].second) && testta != 0 && testtb != 0)
  79. std::cout << "Remis\n";
  80. else if (testta == 0 && testtb != 0)
  81. std::cout << "Karol\n";
  82. else if (testtb == 0 && testta != 0)
  83. std::cout << "Tadeusz\n";
  84. else if (a[poma].second < b[pomb].second)
  85. std::cout << "Tadeusz\n";
  86. else
  87. std::cout << "Karol\n";
  88. }
  89.  
  90. delete[] c;
  91. delete[] d;
  92.  
  93. return 0;
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
Success #stdin #stdout 0.01s 5376KB
stdin
3
5 4
1 2
2 2
5
6 4
1 9
6 6
4 5
5 2
stdout
Tadeusz
Karol
Remis
Karol
Tadeusz