{"id":268,"date":"2018-10-29T23:15:33","date_gmt":"2018-10-29T15:15:33","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=268"},"modified":"2018-10-29T23:18:05","modified_gmt":"2018-10-29T15:18:05","slug":"lp2161-shoi2009-%e4%bc%9a%e5%9c%ba%e9%a2%84%e7%ba%a6","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2018\/10\/29\/lp2161-shoi2009-%e4%bc%9a%e5%9c%ba%e9%a2%84%e7%ba%a6\/","title":{"rendered":"lp2161 SHOI2009 \u4f1a\u573a\u9884\u7ea6"},"content":{"rendered":"<p>\u8fd9\u4e00\u9898\u636e\u8bf4\u88ab\u653e\u5728\u4e86\u7ebf\u6bb5\u6811\u8fd9\u4e2a\u6a21\u5757\u4e0b\u9762\u3002<br \/>\n\u6211\u60f3\u4e86\u5f88\u4e45\u5f88\u4e45\u3002\u60f3\u5230\u4e86\u4e00\u79cd\u505a\u6cd5\u3002\u4f46\u662f\u4e00\u5199\u5c31\u611f\u89c9\u5f88\u9ebb\u3002<br \/>\n\u60f3\u7740\u60f3\u7740\uff0c\u7b97\u4e86\u4e00\u4e0b\u590d\u6742\u5ea6\uff0c\u7136\u540e\u5927\u558a\u4e00\u58f0\uff0cMADE\uff01<br \/>\n\u4ed4\u7ec6\u4e00\u60f3\uff0c\u8be2\u95ee2E5\uff0c\u503c\u57df1E5\u3002\u5927\u529b\u4e0a\u5206\u5757\u554a\uff0c\\(O(Nsqrt(M))\\approx 6E7\\)\u4e0d\u6ee1\u3002\u641e\u4ec0\u4e48\u7ebf\u6bb5\u6811\u554a\uff0c\u771f\u662f\u7684\u3002<br \/>\n\u597d\u7684\uff0c\u90a3\u4e48\u5927\u529b\u4e0a\u5206\u5757\u3002<br \/>\n\u5177\u4f53\u5e94\u8be5\u8981\u600e\u4e48\u5206\u5757\u5462\uff1f<br \/>\n\u5bf9\u4e8e\u6bcf\u4e00\u5757\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u79cd\u6807\u8bb0\u3002<br \/>\n\u5982\u679c\u6807\u8bb0\u662f0\uff0c\u8bf4\u660e\u8fd9\u4e2a\u5757\u662f\u7a7a\u7684\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539\uff1b<br \/>\n\u5982\u679c\u6807\u8bb0\u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u8bf4\u660e\u8fd9\u4e2a\u5757\u88ab\u8be5\u6b63\u6574\u6570\u5b8c\u5168\u5305\u542b\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539\uff0c\u5e76\u5c06\u8be5\u6807\u8bb0\u6307\u7684\u6570\u653e\u5165\u5220\u9664\u96c6\u5408\uff1b<br \/>\n\u5982\u679c\u6807\u8bb0\u662f-1\uff0c\u8bf4\u660e\u8fd9\u4e2a\u5757\u91cc\u9762\u5305\u542b\u591a\u4e2a\u8be2\u95ee\u3002\u6b64\u65f6\u540c\u6837\u66b4\u529b\u4fee\u6539\u3002<br \/>\n\u4e3a\u4ec0\u4e48\u8fd9\u6837\u505a\u7684\u590d\u6742\u5ea6\u662f\u5bf9\u7684\u5462\uff1f\u9996\u5148\uff0c\u5982\u679c\u4e00\u4e2a\u5757\uff0c\u5982\u679c\u5b83\u5305\u542b\u591a\u4e2a\u8be2\u95ee\uff0c\u90a3\u4e48\u8981\u4e48\u5b83\u5305\u542b\u7684\u662f\u6574\u4e2a\u8be2\u95ee\uff0c\u8981\u4e48\u5b83\u5305\u542b\u7684\u662f\u8be2\u95ee\u7684\u4e00\u6bb5\u3002<br \/>\n\u56e0\u6b64\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u8be2\u95ee\uff0c\u5b83\u6700\u591a\u53ea\u53ef\u80fd\u88ab\u66b4\u529b\u4fee\u6539\u4e24\u6b21\u3002<br \/>\n\u6240\u4ee5\u8fd9\u79cd\u505a\u6cd5\u662f\u53ef\u884c\u7684\u3002<\/p>\n<p>\u4e0d\u8fc7\u5206\u5757\u5199\u8d77\u6765\u8fd8\u662f\u633a\u9ebb\u7684\u3002\u8c03\u4e86\u534a\u5929\u6ca1\u8c03\u51fa\u6765\uff0c\u7136\u540e\u770b\u5230\u4e86\u4e00\u4e2a\u795e\u4ed9\u505a\u6cd5\uff0c\u5c31\u6284\u8fc7\u6765\u4e86\uff1a<br \/>\n\u5177\u4f53\u6765\u8bf4\uff0c\u5c31\u662f\u628aSet\u5f53\u4f5c\u7ea2\u9ed1\u6811\u7528\u3002<br \/>\n\u592a\u731b\u4e86\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"cpp\">#include&lt;cmath&gt;\r\n#include\r\n#include\r\n#include&lt;cstring&gt;\r\n#include&lt;set&gt; \r\nusing namespace std;\r\n#define MAXN 100000\r\nint n;\r\nstruct data{\r\n\tint l,r;\r\n\tbool operator &lt;(const data &amp;A)const{\r\n\t\treturn (this-&gt;l==A.l)?(this-&gt;l&lt;A.r):(this-&gt;l&lt;A.l);\r\n\t}\r\n};\r\n\r\nset&lt;data&gt; st;\r\nvoid init(){\r\n\tscanf(\"%d\",&amp;n);\r\n\tchar ch[5];\r\n\tint l,r,ans;\r\n\tfor(int i=1;i&lt;=n;++i){\r\n\t\tcin&gt;&gt;ch;\r\n\t\tif(ch[0]=='B'){\r\n\t\t\tprintf(\"%lld\\n\",st.size());\r\n\t\t}else{\r\n\t\t\tscanf(\"%d%d\",&amp;l,&amp;r);\r\n\t\t\tdata X=(data){l,r};\r\n\t\t\tans=0;\r\n\t\t\tset&lt;data&gt;::iterator it=st.lower_bound(X);\r\n\t\t\twhile(1){\r\n\t\t\t\tit=st.lower_bound(X);\r\n\t\t\t\tif(it-&gt;l&lt;=X.r&amp;&amp;X.l&lt;=it-&gt;r){\r\n\t\t\t\t\t++ans;\r\n\t\t\t\t\tst.erase(it);\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tit=st.lower_bound(X);\r\n\t\t\t\tif(it!=st.begin()){\r\n\t\t\t\t\t--it;\r\n\t\t\t\t\tif(it-&gt;l&lt;=X.r&amp;&amp;X.l&lt;=it-&gt;r){\r\n\t\t\t\t\t\t++ans;\r\n\t\t\t\t\t\tst.erase(it);\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tst.insert(X);\r\n\t\t\tprintf(\"%d\\n\",ans);\r\n\t\t}\r\n\t}\r\n}\r\nint main(){\r\n\tinit();\r\n\treturn 0;\r\n}\r\n<\/code><\/pre>\n<pre class=\"pure-highlightjs\"><code class=\"cpp\">\r\n\/\/\u5927\u529b\u5206\u5757\u7684\u5047\u505a\u6cd5\uff0c\u76f4\u5230\u73b0\u5728\u90fd\u4e0d\u61c2bug\u5728\u54ea\u91cc\u3002\u7b2ck\u5757\u8868\u793ak*blck~(k+1)*blck-1\u7684\u503c\u3002 \r\nint n,cnt=0,blck,L[200005],R[200005],rst,TOP;\r\nint V[317],v[100005];\r\nchar ch[4];\r\nbool bo[200005];\r\ninline void prpr(){\r\n    blck=sqrt(MAXN);\r\n    rst=MAXN%blck;\r\n    TOP=MAXN-rst;\r\n    memset(V,0,sizeof(V));\r\n    memset(v,0,sizeof(v));\r\n    memset(bo,0,sizeof(bo));\r\n}\r\nint rt=0;\r\ninline void delB(const int &amp;l,const int &amp;r,const int &amp;x){\r\n    for(int i=l;i&lt;=r;++i){\r\n        if(V[i]==x){\r\n            V[i]=0;\r\n        }\r\n    }\r\n}\r\ninline void delb(const int &amp;l,const int &amp;r,const int &amp;x){\r\n    for(int i=l;i&lt;=r;++i){\r\n        if(v[i]==x){\r\n            v[i]=0;\r\n        }\r\n    }\r\n}\r\ninline void del(const int &amp;x){\r\n    bo[x]=0;\r\n    ++rt;--cnt;\r\n    int l=L[x],r=R[x];\r\n    if(r\/blck-1&lt;(l\/blck+1)){\r\n        delb(l,r,x);\r\n        return;\r\n    }\r\n    delB(l\/blck+1,r\/blck-1,x);\r\n    delb(l,(l\/blck+1)*blck-1,x),delb((r\/blck)*blck,r,x);\r\n    \r\n}\r\ninline void addb(const int &amp;l,const int &amp;r,const int &amp;x){\r\n    for(int i=l;i&lt;=r;++i){\r\n    \tif(V[i\/blck]!=x){\r\n    \t\tV[i\/blck]=-1;\r\n\t\t} \r\n        if(!bo[v[i]]){\r\n            v[i]=x;\r\n        }else{\r\n            del(v[i]);\r\n            v[i]=x;\r\n        }\r\n    }\r\n}\r\ninline void clr(const int &amp;x){\r\n    for(int i=x*blck;i&lt;(x+1)*blck;++i){\r\n        if(bo[v[i]]){\r\n            del(v[i]);\r\n        }\r\n    }\r\n}\r\ninline void addB(const int &amp;l,const int &amp;r,const int &amp;x){\r\n    for(int i=l;i&lt;=r;++i){\r\n        if(!V[i]){\r\n            V[i]=x;\r\n        }else if(V[i]&gt;0){\r\n            if(bo[V[i]]){\r\n                del(V[i]);\r\n            }\r\n            V[i]=x;\r\n        }else{\r\n            clr(i);\r\n            V[i]=x;\r\n        }\r\n    }\r\n}\r\ninline int add(const int &amp;l,const int &amp;r,const int &amp;x){\r\n    rt=0;\r\n    if(r\/blck-1&lt;(l\/blck+1)){\r\n        addb(l,r,x);\r\n        return rt;\r\n    }\r\n    addB(l\/blck+1,r\/blck-1,x);\r\n    addb(l,(l\/blck+1)*blck-1,x),addb((r\/blck)*blck,r,x);\r\n    return rt;\r\n}\r\nvoid init(){\r\n    prpr();\r\n    scanf(\"%d\",&amp;n);\r\n    int l,r;\r\n    for(int i=1;i&lt;=n;++i){\r\n        cin&gt;&gt;ch;\r\n        if(ch[0]=='B'){\r\n            printf(\"%d\\n\",cnt);\r\n        }else{\r\n            bo[i]=1;++cnt;\r\n            scanf(\"%d%d\",&amp;l,&amp;r);\r\n            printf(\"%d\\n\",add(l-1,r-1,i));\r\n            L[i]=l-1,R[i]=r-1;\r\n        }\r\n    }\r\n}\r\nint main(){\r\n    init();\r\n    return 0;\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e00\u9898\u636e\u8bf4\u88ab\u653e\u5728\u4e86\u7ebf\u6bb5\u6811\u8fd9\u4e2a\u6a21\u5757\u4e0b\u9762\u3002 \u6211\u60f3\u4e86\u5f88\u4e45\u5f88\u4e45\u3002\u60f3\u5230\u4e86\u4e00\u79cd\u505a\u6cd5\u3002\u4f46\u662f\u4e00\u5199\u5c31\u611f\u89c9\u5f88\u9ebb\u3002 \u60f3\u7740\u60f3\u7740\uff0c\u7b97\u4e86\u4e00 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2018\/10\/29\/lp2161-shoi2009-%e4%bc%9a%e5%9c%ba%e9%a2%84%e7%ba%a6\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp2161 SHOI2009 \u4f1a\u573a\u9884\u7ea6\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":[8,9,5],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/268"}],"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=268"}],"version-history":[{"count":1,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":269,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/268\/revisions\/269"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}