传送门:http://www.lydsy.com/JudgeOnline/showsource.php?id=1304322
25%思路:因为行数较少,最真实的思路是分块后暴力(也就是可持久化并查集貌似但我不会啊,,有时间会打一下,,但据说会T一组),但行数很少可以利用线段树维护连通性,,每次维护6个量,,查询比较麻烦因为会绕路对吧,,想了好久自己怒写代码一不小心手滑在bzoj上跑的就比鸟哥快了,,开心啊,非常恶心的代码题,,,我这最弱的代码能力看似提高了,,交了一次写错一个统计答案的地方只WA一组,,水数据,,我也是醉了
貌似冬令营wc2009最短路还有一些题都是同一类型的有时间做一下啊,,,
知识点:线段树维护连通性,利用数组下标和位运算减少分情况讨论的次数(splay)中也有,,写代码要想好了再写,写的时候要专心啊,,想好了写会比较简单和容易
(未完)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#define N 100000
using namespace std;
struct node{ bool g[6]; };
int n;
node s[5],A[(N<<2)+5];
bool map[(N<<2)+5];
inline int calc(int x,int y){ return x*(n-1)+y;}
inline int getnum(){
char c; int num;
while (!isdigit(c = getchar()));
num = c - '0';
while (isdigit(c = getchar())) num = 10 *num + c -'0';
return num;
}
void init(){
n = getnum();
s[0] = (node){1,1,0,0,0,0};
s[1] = (node){1,1,1,1,1,1};
memset(map,0,sizeof(map));
memset(A,0,sizeof(A));
}
inline void build(int l,int r,int rt){
int mid = (l+r)>>1;
if (l==r) { A[rt] = s[0]; return;}
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
}
inline node merge(node a,node b,bool x,bool y){
node c;
c.g[0] = (a.g[0]&&x&&b.g[0])||(a.g[4]&&y&&b.g[5]);
c.g[1] = (a.g[1]&&y&&b.g[1])||(a.g[5]&&x&&b.g[4]);
c.g[2] = (a.g[2])||(a.g[0]&&x&&b.g[2]&&y&&a.g[1]);
c.g[3] = (b.g[3])||(b.g[0]&&x&&a.g[3]&&y&&b.g[1]);
c.g[4] = (a.g[0]&&x&&b.g[4])||(a.g[4]&&y&&b.g[1]);
c.g[5] = (b.g[0]&&x&&a.g[5])||(b.g[5]&&y&&a.g[1]);
return c;
}
inline void insert(int l,int r,int rt,int x1,int y1,int x2,int y2,bool c){
int mid = (l+r)>>1,y = min(y1,y2);
if (x1==x2&&y==mid) { map[calc(x1,y)] = c; A[rt] = merge(A[rt<<1],A[rt<<1|1],map[calc(0,mid)],map[calc(1,mid)]); return;}
else if (x1!=x2&&l==r) { map[2*(n-1)+y] = c; A[rt] = s[c]; return;}
if (y<=mid) insert(l,mid,rt<<1,x1,y1,x2,y2,c);
if (y>mid) insert(mid+1,r,rt<<1|1,x1,y1,x2,y2,c);
A[rt] = merge(A[rt<<1],A[rt<<1|1],map[calc(0,mid)],map[calc(1,mid)]);
}
inline node query(int l,int r,int rt,int ll,int rr){
int mid = (r+l)>>1;
if (l>=ll&&r<=rr) return A[rt];
if (rr<=mid) return query(l,mid,rt<<1,ll,rr);
if (ll>mid) return query(mid+1,r,rt<<1|1,ll,rr);
else return merge(query(l,mid,rt<<1,ll,rr),query(mid+1,r,rt<<1|1,ll,rr),map[calc(0,mid)],map[calc(1,mid)]);
}
inline void ask(int x1,int y1,int x2,int y2){
bool ans;
if (y1>y2) swap(x1,x2),swap(y1,y2);
s[2] = query(1,n,1,y1,y2);
//for (int i = 0;i < 6; ++i) cout<<s[2].g[i]<<" ";
//cout<<endl;
s[3] = query(1,n,1,1,y1);
//for (int i = 0;i < 6; ++i) cout<<s[3].g[i]<<" ";
//cout<<endl;
s[4] = query(1,n,1,y2,n);
//for (int i = 0;i < 6; ++i) cout<<s[4].g[i]<<" ";
cout<<endl;
if (x1==x2)
ans = (s[2].g[x1])||(s[3].g[3]&&s[2].g[4+x1^1])||(s[4].g[2]&&s[2].g[4+x1])||(s[3].g[3]&&s[4].g[2]&&s[2].g[x1^1]);
if (x1!=x2)
ans = (s[2].g[4+x1])||(s[3].g[3]&&s[2].g[x1^1])||(s[4].g[2]&&s[2].g[x1])||(s[3].g[3]&&s[4].g[2]&&s[2].g[4+x1^1]);
if (ans) puts("Y");
else puts("N");
}
void DO_IT(){
char ch[6];
int x1,y1,x2,y2;
scanf("%s",ch);
while (ch[0]!='E'){
x1 = getnum()-1; y1 = getnum(); x2 = getnum()-1; y2 = getnum();
if (ch[0] == 'O') insert(1,n,1,x1,y1,x2,y2,1);
if (ch[0] == 'C') insert(1,n,1,x1,y1,x2,y2,0);
if (ch[0] == 'A') ask(x1,y1,x2,y2);
scanf("%s",ch);
}
}
int main(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
init();
build(1,n,1);
DO_IT();
//fclose(stdin); fclose(stdout);
return 0;
}