{"id":854,"date":"2019-04-04T23:57:07","date_gmt":"2019-04-04T15:57:07","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=854"},"modified":"2019-04-12T15:58:44","modified_gmt":"2019-04-12T07:58:44","slug":"lp4332-shoi2014-%e4%b8%89%e5%8f%89%e7%a5%9e%e7%bb%8f%e6%a0%91","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2019\/04\/04\/lp4332-shoi2014-%e4%b8%89%e5%8f%89%e7%a5%9e%e7%bb%8f%e6%a0%91\/","title":{"rendered":"lp4332 SHOI2014 \u4e09\u53c9\u795e\u7ecf\u6811"},"content":{"rendered":"\n<p>\u6211\u4eec\u77e5\u9053\uff0c\u6bcf\u4e00\u4e2a\\(x_{i}\\)\u5404\u4e0d\u76f8\u540c\u3002\u8fd9\u542f\u53d1\u6211\u4eec\uff0c\u8fd9\u4e00\u9898\u7684\u70b9\u5c06\u5f62\u6210\u4e00\u68f5\u6811\u7684\u7ed3\u6784\u3002<br> \u4ed4\u7ec6\u89c2\u5bdf\u9898\u76ee\u63cf\u8ff0\uff0c\u6211\u4eec\u53d1\u73b0\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u70b9\uff0c\u5b83\u7684\u4fee\u6539\u5f71\u54cd\u5230\u7684\u6709\u4e14\u4ec5\u6709\u5b83\u7684\u7956\u5148\u3002<br> \u6211\u4eec\u4e0d\u59a8\u8bbe\u4e00\u4e2a\u70b9\u7684\u6743\u503c\u4e3a\u5b83\u7684\u5b50\u8282\u70b9\u4eec\u4e2d\u4fe1\u53f7\u4e3a1\u7684\u4e2a\u6570\u3002\u90a3\u4e48\u6839\u636e\u9898\u76ee\u7ed9\u51fa\u7684\u6027\u8d28\uff0c\u5f53\u4e14\u4ec5\u5f53\u67d0\u4e2a\u8282\u70b9\u7684\u6743\u503c\u4e3a1\u7684\u65f6\u5019\u5b83\u7684\u67d0\u4e2a0\u5b50\u8282\u70b9\u53d8\u62101\uff0c\u6216\u8005\u67d0\u4e2a\u8282\u70b9\u7684\u6743\u503c\u4e3a2\u7684\u65f6\u5019\u5b83\u7684\u67d0\u4e2a1\u5b50\u8282\u70b9\u53d8\u62100\uff0c\u8fd9\u4e2a\u4fe1\u53f7\u624d\u4f1a\u7ee7\u7eed\u5411\u4e0a\u4f20\u8f93\u3002\u5bb9\u6613\u53d1\u73b0\uff0c\u8fd9\u6837\u7684\u4f20\u8f93\u8986\u76d6\u7684\u662f\u4e14\u603b\u662f\u67d0\u4e00\u6761\u7ad6\u76f4\u4e0a\u4e0b\u7684\u51681\/\u51682\u94fe\u3002<br> \u8be6\u7ec6\u5730\u8bf4\uff0c\u5982\u679c\u4fee\u6539\u7684\u53f6\u5b50\u8282\u70b9\u662f0\u53d8\u62101\uff0c\u90a3\u4e48\u5f71\u54cd\u5230\u7684\u5c31\u662f\u4ece\u5b83\u62c9\u51fa\u7684\u4e00\u6761\u7ad6\u76f4\u5411\u4e0a\u7684\u51681\u94fe\u4ee5\u53ca\u8fd9\u6761\u94fe\u7684\u7236\u4eb2\uff1b\u5982\u679c\u4fee\u6539\u7684\u53f6\u5b50\u8282\u70b9\u662f1\u53d8\u62100\uff0c\u90a3\u4e48\u5f71\u54cd\u5230\u7684\u5c31\u662f\u4ece\u5b83\u62c9\u51fa\u7684\u4e00\u6761\u7ad6\u76f4\u5411\u4e0a\u7684\u51682\u94fe\u4ee5\u53ca\u8fd9\u6761\u94fe\u7684\u7236\u4eb2\u3002<br> \u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u5728LCT\u5256\u51fa\u7684\u5b9e\u94fe\u4e0a\u7ef4\u62a4\u51681\u94fe\u4ee5\u53ca\u51682\u94fe\uff0c\u7136\u540e\u4fee\u6539\u7684\u65f6\u5019\u4fee\u6539\u4e00\u6574\u6761\u94fe\u3002\u8fd9\u5c31\u5b8c\u6210\u4e86\u8fd9\u9898\u7684\u8981\u6c42\u3002<br> \u4f46\u662f\u4ed4\u7ec6\u60f3\u60f3\uff0c\u6211\u4eec\u4f1a\u53d1\u73b0\uff0c\u7ef4\u62a4\u51681\u94fe\u548c\u51682\u94fe\u4f1a\u663e\u5f97\u5f88\u9ebb\u3002\u6240\u4ee5\u6211\u4eec\u4e0d\u59a8\u6539\u4e3a\u7ef4\u62a4\u6df1\u5ea6\u6700\u6df1\u7684\u975e1\u8282\u70b9\u548c\u975e2\u8282\u70b9\u3002\u5bf9\u4e8e\u5c060\u53d8\u4e3a1\u7684\u64cd\u4f5c\uff0c\u6211\u4eec\u627e\u5230\u6df1\u5ea6\u6700\u6df1\u7684\u975e1\u8282\u70b9\uff0c\u628a\u5b83\u65cb\u5230\u6839\uff0c\u7136\u540e\u4fee\u6539\u5373\u53ef\uff0c\u5982\u679c\u6df1\u5ea6\u6700\u6df1\u7684\u975e1\u8282\u70b9\u4e0d\u5b58\u5728\uff0c\u90a3\u5c31\u610f\u5473\u7740\u6839\u8282\u70b9\u4e5f\u662f1\uff0c\u90a3\u4e48\u7b54\u6848\u5c31\u4f1a\u53d1\u751f\u53d8\u5316\uff1b\u5bf9\u4e8e\u5c061\u53d8\u4e3a0\u7684\u64cd\u4f5c\uff0c\u5982\u6cd5\u70ae\u5236\u3002<br> \u53e6\u5916\uff0c\u7531\u4e8e\u8fd9\u4e00\u9898\u53ea\u6709\u7ad6\u76f4\u4e0a\u4e0b\u7684\u94fe\u7684\u64cd\u4f5c\uff0c\u6240\u4ee5\u6211\u4eec\u751a\u81f3\u4e0d\u9700\u8981\u5199\u6362\u6839\u51fd\u6570\u3002\u5f53\u7136\uff0c\u7531\u4e8e\u8fd9\u4e00\u9898\u6ca1\u6709\u5206\u79bb\u548c\u5408\u5e76\u64cd\u4f5c\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u4e5f\u4e0d\u9700\u8981\u5199\u5206\u79bb\u548c\u5408\u5e76\u51fd\u6570\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>\nusing namespace std;\n\ninline void Swap(int &amp;A,int &amp;B){\n\tA^=B^=A^=B;\n}\nconst int N=500005;\nint fa[N*3],ch[N*3][2],val[N*3],n1[N*3],n2[N*3],lzy[N*3];\n\/\/\u5148\u770b\u53f3\u5b50\u8282\u70b9\uff08\u4e0b\u65b9\uff09\u662f\u5426\u5b58\u5728\uff0c\u518d\u770b\u672c\u8282\u70b9\u662f\u5426\u6ee1\u8db3\u8981\u6c42\uff0c\u7136\u540e\u770b\u5de6\u5b50\u8282\u70b9\uff08\u4e0a\u65b9\uff09\u662f\u5426\u5b58\u5728\u3002 \ninline void updt(int X){\n\tn1[X]=n1[ch[X][1]]?n1[ch[X][1]]:(val[X]==1?n1[ch[X][0]]:X);\n\tn2[X]=n2[ch[X][1]]?n2[ch[X][1]]:(val[X]==2?n2[ch[X][0]]:X);\n}\ninline void rnw(int X,int V){\n\tval[X]^=3,Swap(n1[X],n2[X]),lzy[X]+=V;\n}\ninline void pshd(int X){\n\tif(lzy[X]!=0){\n\t\trnw(ch[X][0],lzy[X]);rnw(ch[X][1],lzy[X]);lzy[X]=0;\n\t}\n}\ninline bool fndD(int X){\n\treturn ch[fa[X]][1]==X;\n}\ninline bool ntrt(int X){\n\treturn ch[fa[X]][0]==X||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*3];\ninline void splay(int X){\n\tint Y=X,Z=0;\n\tst[++Z]=Y;\n\twhile(ntrt(Y)){\n\t\tY=fa[Y];\n\t\tst[++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}\nint n,Q,in[N*3];\nstd::queue&lt;int> q;\nvoid init(){\n\tscanf(\"%d\",&amp;n);\n\tint x,y,z;\n\tfor(int i=1;i&lt;=n;++i){\n\t\tscanf(\"%d%d%d\",&amp;x,&amp;y,&amp;z);\n\t\tfa[x]=fa[y]=fa[z]=i;\n\t\tin[i]=3;\n\t}\n\tfor(int i=1;i&lt;=(n&lt;&lt;1|1);++i){\n\t\tscanf(\"%d\",&amp;x);\n\t\tq.push(i+n);\n\t\tval[i+n]=x&lt;&lt;1;\n\t}\n\twhile(!q.empty()){\n\t\tx=q.front();\n\t\tq.pop();\n\t\tif(x&lt;=n){\n\t\t\tupdt(x);\n\t\t}\n\t\tval[fa[x]]+=val[x]>>1;\n\t\t--in[fa[x]];\n\t\tif(!in[fa[x]]){\n\t\t\tq.push(fa[x]);\n\t\t}\n\t}\n\tscanf(\"%d\",&amp;Q);\n\tint tp,nwrt=val[1]>>1;\n\tfor(int i=1;i&lt;=Q;++i){\n\t\tscanf(\"%d\",&amp;x);\n\t\ttp=(val[x]^=2)-1;\n\t\tx=fa[x];\n\t\taccess(x),splay(x);\n\t\tif((~tp?n1:n2)[x]){\n\t\t\tx=(~tp?n1:n2)[x];\n\t\t\tsplay(x);\n\t\t\trnw(ch[x][1],tp),updt(ch[x][1]);\n\t\t\tval[x]+=tp;updt(x);\n\t\t}else{\n\t\t\trnw(x,tp);updt(x);\n\t\t\tnwrt^=1;\n\t\t}\n\t\tputs(nwrt?\"1\":\"0\");\n\t}\n}\nint main(){\n\tinit();\n\treturn 0;\n}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u77e5\u9053\uff0c\u6bcf\u4e00\u4e2a\\(x_{i}\\)\u5404\u4e0d\u76f8\u540c\u3002\u8fd9\u542f\u53d1\u6211\u4eec\uff0c\u8fd9\u4e00\u9898\u7684\u70b9\u5c06\u5f62\u6210\u4e00\u68f5\u6811\u7684\u7ed3\u6784\u3002 \u4ed4\u7ec6\u89c2\u5bdf\u9898\u76ee\u63cf\u8ff0\uff0c\u6211\u4eec &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2019\/04\/04\/lp4332-shoi2014-%e4%b8%89%e5%8f%89%e7%a5%9e%e7%bb%8f%e6%a0%91\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp4332 SHOI2014 \u4e09\u53c9\u795e\u7ecf\u6811\u201d<\/span><\/a><\/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\/854"}],"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=854"}],"version-history":[{"count":2,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/854\/revisions"}],"predecessor-version":[{"id":868,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/854\/revisions\/868"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=854"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}