1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 using namespace std;
7 const int N = 100010;
8 #define Ch1 (i<<1)
9 #define Ch2 (i<<1)|1
10 #define For(i,n) for(int i=1;i<=n;i++)
11 #define Rep(i,l,r) for(int i=l;i<=r;i++)
12
13 struct Link{
14 bool lb,rb,b[2][2];
15 }Left,Right,Mid;
16 struct tnode{
17 int l,r,mid;
18 bool b0,b1;Link b;
19 }T[N*4];
20 char op[10];
21 bool ans;
22 int n,x1,x2,y1,y2;
23
24 Link Merge(Link Left,Link Right,bool b0,bool b1){
25 Link merged;
26 merged.lb = Left.lb||(( Left.b[0][0])&&( Left.b[1][1])&&(b0)&&(b1)&&(Right.lb));
27 merged.rb = Right.rb||((Right.b[0][0])&&(Right.b[1][1])&&(b0)&&(b1)&&(Left.rb));
28 memset(merged.b,false,sizeof(merged.b));
29 if(b0) Rep(i,0,1)
30 Rep(j,0,1) merged.b[i][j] |= Left.b[i][0] && Right.b[0][j];
31 if(b1) Rep(i,0,1)
32 Rep(j,0,1) merged.b[i][j] |= Left.b[i][1] && Right.b[1][j];
33 return merged;
34 }
35
36 void Build(int l,int r,int i){
37 T[i].l = l; T[i].r = r; T[i].mid = (l+r)>>1;
38 if(l==r){
39 T[i].b.b[0][0] = T[i].b.b[1][1] = true;
40 return;
41 }
42 Build(l,T[i].mid,Ch1); Build(T[i].mid+1,r,Ch2);
43 }
44
45 Link query(int l,int r,int i){
46 if(l<=T[i].l&&T[i].r<=r) return T[i].b;
47 if(r<=T[i].mid) return query(l,r,Ch1);
48 if(l>T[i].mid) return query(l,r,Ch2);
49 return Merge(query(l,r,Ch1),query(l,r,Ch2),T[i].b0,T[i].b1);
50 }
51
52 void Modify(int i,bool change){
53 if((x1==x2)&&(y1==T[i].mid)){
54 if(x1) T[i].b1 = change;else T[i].b0 = change;
55 T[i].b = Merge(T[Ch1].b,T[Ch2].b,T[i].b0,T[i].b1);
56 }else if(T[i].l==T[i].r)
57 T[i].b.lb = T[i].b.rb = T[i].b.b[0][1] = T[i].b.b[1][0] = change;
58 else{
59 if(y2>T[i].mid) Modify(Ch2,change);
60 else Modify(Ch1,change);
61 T[i].b = Merge(T[Ch1].b,T[Ch2].b,T[i].b0,T[i].b1);
62 }
63 }
64
65 int main(){
66 scanf("%d",&n);
67 Build(1,n,1);
68 for(;;){
69 scanf("%s",op);
70 if(!strcmp("Exit",op)) return 0;
71 scanf("%d%d%d%d",&x1,&y1,&x2,&y2);x1--;x2--;
72 if(y1>y2) swap(y1,y2),swap(x1,x2);
73 if(!strcmp("Open",op)) Modify(1,true);
74 if(!strcmp("Close",op)) Modify(1,false);
75 if(!strcmp("Ask",op)){
76 Left = query(1,y1,1);
77 Right = query(y2,n,1);
78 Mid = query(y1,y2,1);
79 bool ans = false;
80 Rep(i,0,1)
81 Rep(j,0,1)
82 if(Mid.b[i][j])
83 if((i==x1||Left.rb)&&(j==x2||Right.lb)) ans = true;
84 if(ans) puts("Y");else puts("N");
85 }
86 }
87 return 0;
88 }