fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int Q;
  8. cin >> Q;
  9.  
  10. while (Q--) {
  11. int x, y;
  12. cin >> x >> y;
  13.  
  14. // Determine the level of the triangle
  15. int level = 0;
  16. while (x > 1) {
  17. x /= 2;
  18. level++;
  19. }
  20.  
  21. // Calculate the number of points in the previous level
  22. int prevLevelPoints = pow(2, level - 1) - 1;
  23.  
  24. // Determine the position of the point within the level, starting from 0
  25. int position = y - 1;
  26.  
  27. // Determine the color based on the position within the level
  28. if (position < prevLevelPoints) {
  29. cout << 1 << endl; // Red
  30. } else {
  31. // Check if the position is in the inverted triangle or the bottom triangle
  32. int invertedTrianglePoints = prevLevelPoints;
  33. if (position < invertedTrianglePoints + prevLevelPoints + 1) {
  34. cout << 0 << endl; // Blue
  35. } else {
  36. cout << 1 << endl; // Red
  37. }
  38. }
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5296KB
stdin
6
1 1
5 3
8 2
8 6
5 4
6 4
stdout
0
0
1
0
1
1