1 /**************************************************************
2 Problem: 1018
3 User: Tunix
4 Language: C++
5 Result: Accepted
6 Time:1068 ms
7 Memory:4208 kb
8 ****************************************************************/
9
10 //BZOJ 1018
11 #include<vector>
12 #include<cstdio>
13 #include<cstring>
14 #include<cstdlib>
15 #include<iostream>
16 #include<algorithm>
17 #define rep(i,n) for(int i=0;i<n;++i)
18 #define F(i,j,n) for(int i=j;i<=n;++i)
19 #define D(i,j,n) for(int i=j;i>=n;--i)
20 #define pb push_back
21 using namespace std;
22 inline int getint(){
23 int v=0,sign=1; char ch=getchar();
24 while(ch<‘0‘||ch>‘9‘){ if (ch==‘-‘) sign=-1; ch=getchar();}
25 while(ch>=‘0‘&&ch<=‘9‘){ v=v*10+ch-‘0‘; ch=getchar();}
26 return v*sign;
27 }
28 const int N=1e5+10,INF=~0u>>2;
29 typedef long long LL;
30 /******************tamplate*********************/
31 int n;
32 struct node{
33 bool z,y,s,x,zs,zx;
34 node(bool z=0,bool y=0,bool s=0,bool x=0,bool zs=0,bool zx=0):
35 z(z),y(y),s(s),x(x),zs(zs),zx(zx){}
36 //z 左端两结点是否连通
37 //y 右端
38 //s 上方
39 //x 下方
40 //zs 左上->右下
41 //zx 左下->右上
42 }a[N],t[N<<2],ans;
43 #define L (o<<1)
44 #define R (o<<1|1)
45 #define mid (l+r>>1)
46 void maintain(node &a){
47 a.zs|=(a.z&a.x) | (a.s&a.y);
48 a.zx|=(a.z&a.s) | (a.x&a.y);
49 a.z|=(a.zs&a.x) | (a.zx&a.s);
50 a.y|=(a.zs&a.s) | (a.zx&a.x);
51 a.s|=(a.zs&a.y) | (a.zx&a.z);
52 a.x|=(a.zs&a.z) | (a.zx&a.y);
53 }
54 node Union(node x,node y){
55 node tmp;
56 tmp.z =x.z; tmp.y=y.y;
57 tmp.s =(x.s&y.s) | (x.zs&y.zx) ;
58 tmp.x =(x.x&y.x) | (x.zx&y.zs) ;
59 tmp.zs=(x.s&y.zs) | (x.zs&y.x) ;
60 tmp.zx=(x.x&y.zx) | (x.zx&y.s) ;
61 return tmp;
62 }
63 void update(int o,int l,int r,int pos,int num,bool v){
64 //将pos位置的num号连通情况改为v
65 if (l==r){
66 if (num==1) a[l].z=v; if (num==2) a[l].y=v;
67 if (num==3) a[l].s=v; if (num==4) a[l].x=v;
68 t[o]=a[l];
69 }else{
70 if (pos<=mid) update(L,l,mid,pos,num,v);
71 else update(R,mid+1,r,pos,num,v);
72 t[o]=Union(t[L],t[R]);
73 }
74 maintain(t[o]);
75 }
76 int ql,qr;bool sign=0;
77 void query(int o,int l,int r){
78 if (ql<=l && qr>=r){
79 if (!sign) {ans=t[o];sign=1;}
80 else ans=Union(ans,t[o]);
81 }
82 else{
83 if (ql<=mid) query(L,l,mid);
84 if (qr>mid) query(R,mid+1,r);
85 }
86 }
87 int main(){
88 #ifndef ONLINE_JUDGE
89 freopen("1018.in","r",stdin);
90 freopen("1018.out","w",stdout);
91 #endif
92 n=getint()-1;
93 int r1,r2,c1,c2;
94 char cmd[10];
95 while(scanf("%s",cmd)!=EOF && cmd[0]!=‘E‘){
96 r1=getint(); c1=getint(); r2=getint(); c2=getint();
97 if (c1>c2){swap(c1,c2); swap(r1,r2);}
98 if (cmd[0]==‘A‘){
99 ans=node();
100 if (c1==c2){
101 if (c1<n+1 && c1>1){//不是右端点
102 node t1,t2;
103 ql=1; qr=c1-1; sign=0;
104 query(1,1,n); t1=ans;
105 ql=c1; qr=n; sign=0;
106 query(1,1,n);
107 ans.z|=t1.y; ans.z|=t2.z;
108 puts(ans.z?"Y":"N");
109 }else if(c1==n+1){
110 ans=t[1];
111 puts(ans.y?"Y":"N");
112 }else{
113 ans=t[1];
114 puts(ans.z?"Y":"N");
115 }
116 }else{
117 node t1,t2;
118 if (c1!=1){ql=1; qr=c1-1; sign=0; query(1,1,n); t1=ans;}
119 if (c2!=n+1){ql=c2; qr=n; sign=0; query(1,1,n); t2=ans;}
120 ql=c1; qr=c2-1; sign=0;
121 query(1,1,n);
122 ans.z|=t1.y | (t1.s & t1.z & t1.x);
123 ans.y|=t2.z | (t2.s & t2.y & t2.x);
124 maintain(ans);
125 if (r1==1 && r2==1) puts(ans.s ?"Y":"N");
126 if (r1==2 && r2==2) puts(ans.x ?"Y":"N");
127 if (r1==1 && r2==2) puts(ans.zs?"Y":"N");
128 if (r1==2 && r2==1) puts(ans.zx?"Y":"N");
129 }
130 }else{
131 bool type=0;
132 if (cmd[0]==‘O‘) type=1;
133 else type=0;
134 if (r1==r2){
135 if (r1==1) update(1,1,n,c1,3,type);
136 else update(1,1,n,c1,4,type);
137 }else{
138 if (c1<n+1) update(1,1,n,c1,1,type);
139 if (c1>1 ) update(1,1,n,c1-1,2,type);
140 }
141 }
142 }
143 return 0;
144 }
145