fork download
  1. #include <cmath>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <algorithm>
  8. #include <queue>
  9.  
  10. #define rep(i, l, r) for(int i = l; i <= r; i++)
  11. #define down(i, l, r) for(int i = l; i >= r; i--)
  12. #define MS 345678
  13. #define MAX 1037471823
  14. #define Q 103
  15.  
  16. using namespace std;
  17.  
  18. struct node
  19. {
  20. bool a, b, c, d, e, f;
  21. } t[MS], p[MS], a, ll, mm, rr, ls, k;
  22. int n, a1, b1, a2, b2, x, y, kk;
  23. char s[9];
  24. bool c, b[5];
  25.  
  26. void Change3(int o)
  27. {
  28. ls.a = a.a || (a.b && t[o].a && a.d) || (a.e && t[o].a && a.f);
  29. ls.b = (a.b && t[o].b) || (a.e && t[o].f);
  30. ls.c = t[o].c || (t[o].b && a.c && t[o].d) || (t[o].e && a.c && t[o].f);
  31. ls.d = (a.d && t[o].d) || (a.f && t[o].e);
  32. ls.e = (a.e && t[o].d) || (a.b && t[o].e);
  33. ls.f = (a.f && t[o].b) || (a.d && t[o].f);
  34. a.a = ls.a, a.b = ls.b, a.c = ls.c, a.d = ls.d, a.e = ls.e, a.f = ls.f;
  35. }
  36.  
  37. void Change2(int o, int x)
  38. {
  39. t[o].a = p[x].a || (p[x].b && p[x].c && p[x].d);
  40. t[o].b = p[x].b || (p[x].c && p[x].d && p[x].a);
  41. t[o].c = p[x].c || (p[x].d && p[x].a && p[x].b);
  42. t[o].d = p[x].d || (p[x].a && p[x].b && p[x].c);
  43. t[o].e = (p[x].a && p[x].d) || (p[x].b && p[x].c);
  44. t[o].f = (p[x].a && p[x].b) || (p[x].c && p[x].d);
  45. }
  46.  
  47. void Change(int o)
  48. {
  49. t[o].a = t[o*2].a || (t[o*2].b && t[o*2+1].a && t[o*2].d) || (t[o*2].e && t[o*2+1].a && t[o*2].f);
  50. t[o].b = (t[o*2].b && t[o*2+1].b) || (t[o*2].e && t[o*2+1].f);
  51. t[o].c = t[o*2+1].c || (t[o*2+1].b && t[o*2].c && t[o*2+1].d) || (t[o*2+1].e && t[o*2].c && t[o*2+1].f);
  52. t[o].d = (t[o*2].d && t[o*2+1].d) || (t[o*2].f && t[o*2+1].e);
  53. t[o].e = (t[o*2].e && t[o*2+1].d) || (t[o*2].b && t[o*2+1].e);
  54. t[o].f = (t[o*2].f && t[o*2+1].b) || (t[o*2].d && t[o*2+1].f);
  55. }
  56.  
  57. void Edit1(int l, int r, int o)
  58. {
  59. if (l == r)
  60. {
  61. if (a1 == 1) p[l].b = c; else p[l].d = c;
  62. Change2(o, l);
  63. return;
  64. }
  65. int m = (l+r)/2;
  66. if (b1 <= m) Edit1(l, m, o*2); else Edit1(m+1, r, o*2+1);
  67. Change(o);
  68. }
  69.  
  70. void Edit2(int l, int r, int o)
  71. {
  72. if (l == r)
  73. {
  74. if (l == b1) p[l].a = c; else p[l].c = c;
  75. Change2(o, l);
  76. return;
  77. }
  78. int m = (l+r)/2;
  79. if (b1-1 <= m) Edit2(l, m, o*2);
  80. else if (m+1 <= b1) Edit2(m+1, r, o*2+1);
  81. Change(o);
  82. }
  83.  
  84. void Ask(int l, int r, int o)
  85. {
  86. if (x <= l && r <= y)
  87. {
  88. Change3(o);
  89. return;
  90. }
  91. int m = (l+r)/2;
  92. if (x <= m) Ask(l, m, o*2);
  93. if (m+1 <= y) Ask(m+1, r, o*2+1);
  94. }
  95.  
  96. int main()
  97. {
  98. scanf("%d%s", &n, s);
  99. k.b = k.d = true, k.a = k.c = k.e = k.f = false;
  100. while (s[0] != 'E')
  101. {
  102. scanf("%d%d%d%d", &a1, &b1, &a2, &b2);
  103. if (b1 > b2) kk = a1, a1 = a2, a2 = kk, kk = b1, b1 = b2, b2 = kk;
  104. if (s[0] == 'O')
  105. {
  106. c = true;
  107. if (a1 == a2) Edit1(1, n-1, 1); else Edit2(1, n-1, 1);
  108. }
  109. else if (s[0] == 'C')
  110. {
  111. c = false;
  112. if (a1 == a2) Edit1(1, n-1, 1); else Edit2(1, n-1, 1);
  113. }
  114. else if (s[0] == 'A')
  115. {
  116. ll.a = k.a, ll.b = k.b, ll.c = k.c, ll.d = k.d, ll.e = k.e, ll.f = k.f;
  117. mm.a = k.a, mm.b = k.b, mm.c = k.c, mm.d = k.d, mm.e = k.e, mm.f = k.f;
  118. rr.a = k.a, rr.b = k.b, rr.c = k.c, rr.d = k.d, rr.e = k.e, rr.f = k.f;
  119. if (1 <= b1-1)
  120. {
  121. x = 1, y = b1-1;
  122. a.a = k.a, a.b = k.b, a.c = k.c, a.d = k.d, a.e = k.e, a.f = k.f;
  123. Ask(1, n-1, 1);
  124. ll.a = a.a, ll.b = a.b, ll.c = a.c, ll.d = a.d, ll.e = a.e, ll.f = a.f;
  125. }
  126. if (b1 <= b2-1)
  127. {
  128. x = b1, y = b2-1;
  129. a.a = k.a, a.b = k.b, a.c = k.c, a.d = k.d, a.e = k.e, a.f = k.f;
  130. Ask(1, n-1, 1);
  131. mm.a = a.a, mm.b = a.b, mm.c = a.c, mm.d = a.d, mm.e = a.e, mm.f = a.f;
  132. }
  133. if (b2 <= n-1)
  134. {
  135. x = b2, y = n-1;
  136. a.a = k.a, a.b = k.b, a.c = k.c, a.d = k.d, a.e = k.e, a.f = k.f;
  137. Ask(1, n-1, 1);
  138. rr.a = a.a, rr.b = a.b, rr.c = a.c, rr.d = a.d, rr.e = a.e, rr.f = a.f;
  139. }
  140. if ((a1 == 1 && a2 == 1 && (mm.b || (ll.c && mm.f) || (mm.e && rr.a) || (ll.c && mm.d && rr.a))) ||
  141. (a1 == 1 && a2 == 2 && (mm.e || (ll.c && mm.d) || (mm.b && rr.a) || (ll.c && mm.f && rr.a))) ||
  142. (a1 == 2 && a2 == 1 && (mm.f || (ll.c && mm.b) || (mm.d && rr.a) || (ll.c && mm.e && rr.a))) ||
  143. (a1 == 2 && a2 == 2 && (mm.d || (ll.c && mm.e) || (mm.f && rr.a) || (ll.c && mm.b && rr.a))) )
  144. printf("Y\n");
  145. else printf("N\n");
  146. }
  147. scanf("%s", s);
  148. }
  149. return 0;
  150. }
  151.  
Success #stdin #stdout 0s 7352KB
stdin
2
Open 1 1 1 2
Open 1 2 2 2
Ask 1 1 2 2
Ask 2 1 2 2
Exit
stdout
Y
N