{"id":847,"date":"2019-04-03T16:22:52","date_gmt":"2019-04-03T08:22:52","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=847"},"modified":"2019-04-03T16:23:02","modified_gmt":"2019-04-03T08:23:02","slug":"lp2147-sdoi2008-%e6%b4%9e%e7%a9%b4%e5%8b%98%e6%b5%8b","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2019\/04\/03\/lp2147-sdoi2008-%e6%b4%9e%e7%a9%b4%e5%8b%98%e6%b5%8b\/","title":{"rendered":"lp2147 SDOI2008 \u6d1e\u7a74\u52d8\u6d4b"},"content":{"rendered":"\n<p>\u7ef4\u62a4\u94fe\u63a5\u548c\u65ad\u5f00\uff0cLCT\u88f8\u9898\uff0c\uff08\u770b\u8d77\u6765\uff09\u4e5f\u53ef\u4ee5\u7528\u6309\u79e9\u5408\u5e76\u4f18\u5316\u5e76\u67e5\u96c6\u3002 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include&lt;cstdio>\n#include&lt;cstring>\n#include&lt;algorithm>\n#include&lt;queue>\n#include&lt;vector>\n\n\ninline void Swap(int &amp;A,int &amp;B){\n\tA^=B^=A^=B;\n} \nconst int N=10005;\n\nint fa[N],ch[N][2],rev[N]; \n\ninline void updt(int X){\n\treturn;\n}\ninline void flp(int X){\n\tSwap(ch[X][0],ch[X][1]);\n\trev[X]^=1;\n}\ninline void pshd(int X){\n\tif(rev[X]){\n\t\tflp(ch[X][0]),flp(ch[X][1]);\n\t\trev[X]=0;\n\t}\n}\ninline int ntrt(int X){\n\treturn ch[fa[X]][0]==X||ch[fa[X]][1]==X;\n}\ninline int fndD(int X){\n\treturn ch[fa[X]][1]==X;\n}\ninline void splayOne(int X){\n\tint Y=fa[X],Z=fa[Y],D=fndD(X),D2=fndD(Y),C=ch[X][D^1];\n\tif(ntrt(Y)){\n\t\tch[Z][D2]=X;\n\t}\n\tch[X][D^1]=Y,ch[Y][D]=C;\n\tif(C){\n\t\tfa[C]=Y;\n\t}\n\tfa[Y]=X,fa[X]=Z;\n\tupdt(Y),updt(X);\n}\nint st[N];\ninline void splay(int X){\n\tint Y=X,Z=0;\n\tst[++Z]=Y;\n\twhile(ntrt(Y)){\n\t\tY=fa[Y],st[++Z]=Y;\n\t}\n\twhile(Z){\n\t\tpshd(st[Z--]);\n\t}\n\twhile(ntrt(X)){\n\t\tY=fa[X],Z=fa[Y];\n\t\tif(ntrt(Y)){\n\t\t\tsplayOne(fndD(X)^fndD(Y)?X:Y);\n\t\t}\n\t\tsplayOne(X);\n\t}\n}\ninline void access(int X){\n\tfor(int Y=0;X;Y=X,X=fa[X]){\n\t\tsplay(X),ch[X][1]=Y,updt(X);\n\t}\n}\ninline void chgrt(int X){\n\taccess(X),splay(X),flp(X);\n}\ninline int qryrt(int X){\n\taccess(X),splay(X);\n\twhile(ch[X][0]){\n\t\tpshd(X);\n\t\tX=ch[X][0];\n\t}\n\tsplay(X);\n\treturn X;\n}\ninline void split(int X,int Y){\n\tchgrt(X);\n\taccess(Y),splay(Y);\n}\ninline bool cut(int X,int Y){\n\tsplit(X,Y);\n\tif(ch[Y][0]!=X||ch[X][1]){\n\t\treturn 0;\n\t}\n\tfa[X]=ch[Y][0]=0;\n\treturn 1;\n}\ninline bool link(int X,int Y){\n\tchgrt(X);\n\tif(qryrt(Y)==X){\n\t\treturn 0;\n\t}\n\tfa[X]=Y;\n\treturn 1;\n}\nint n,q;\nchar op[20]; \nvoid init(){\n\tscanf(\"%d%d\",&amp;n,&amp;q);\n\tint x,y;\n\tfor(int i=1;i&lt;=q;++i){\n\t\tstd::cin>>op;\n\t\tscanf(\"%d%d\",&amp;x,&amp;y);\n\t\tswitch(op[0]){\n\t\t\tcase 'C':{\n\t\t\t\tlink(x,y);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'D':{\n\t\t\t\tcut(x,y);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'Q':{\n\t\t\t\tchgrt(x);\n\t\t\t\tputs(qryrt(y)==x?\"Yes\":\"No\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t} \n}\nint main(){\n\tinit();\n\treturn 0;\n}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7ef4\u62a4\u94fe\u63a5\u548c\u65ad\u5f00\uff0cLCT\u88f8\u9898\uff0c\uff08\u770b\u8d77\u6765\uff09\u4e5f\u53ef\u4ee5\u7528\u6309\u79e9\u5408\u5e76\u4f18\u5316\u5e76\u67e5\u96c6\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[30,106,56,70,8,9,6,5],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/847"}],"collection":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/comments?post=847"}],"version-history":[{"count":1,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/847\/revisions"}],"predecessor-version":[{"id":848,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/847\/revisions\/848"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=847"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}