{"id":132,"date":"2010-02-26T15:33:00","date_gmt":"2010-02-26T07:33:00","guid":{"rendered":"http:\/\/localhost\/?p=132"},"modified":"2010-02-26T15:33:00","modified_gmt":"2010-02-26T07:33:00","slug":"jsoi2008_maximum_number_maxnumber_of","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=132","title":{"rendered":"[JSOI2008]\u6700\u5927\u6570maxnumber"},"content":{"rendered":"\n<p>Link\uff1a<a target=\"_blank\" href=\"http:\/\/61.187.179.132:8080\/JudgeOnline\/showproblem?problem_id=1012\">61.187.179.132:8080\/JudgeOnline\/showproblem<\/a><br \/>\u5c31\u662f\u8bf4\u8ba9\u4f60\u7ef4\u62a4\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u3002<br \/>\u652f\u6301\u4e24\u4e2a\u64cd\u4f5c\uff0cA \u5728\u672b\u5c3e\u63d2\u5165\u4e00\u4e2a\u6570\uff0c<br \/>Q L\uff0c\u6700\u540eL\u4e2a\u6570\u4e2d\u6700\u5927\u7684\u662f\u54ea\u4e2a\uff1f<br \/>\u5f88\u660e\u663e\u8981\u7528\u5355\u8c03\u961f\u5217\u3002\u3002\u7528\u4e86\u5355\u8c03\u961f\u5217\u540e\u3002\u3002<br \/>\u6574\u4e2a\u6570\u5217\u88ab\u5206\u6210\u51e0\u6bb5\u6bcf\u6bb5\u7684\u7b54\u6848\u90fd\u662f\u4e00\u6837\u7684\u3002\u3002<br \/>\u90a3\u4e48\u5f04\u4e00\u4e2a\u5e76\u67e5\u96c6\u7ef4\u62a4\u7b54\u6848\u3002\u3002\u7136\u540e\u63d2\u5165\u4e00\u4e2a\u6570\u53ef\u80fd\u5bfc\u81f4\u51e0\u6bb5\u7684\u5408\u5e76\uff0c<br \/>\u5c31\u6b63\u597d\u662f\u5e76\u67e5\u96c6\u7684Union\uff0c\u7136\u540e\u6bcf\u6bb5\u7684\u6839\u5c31\u662f\u8fd9\u6bb5\u7684\u7b54\u6848\u3002\u3002<br \/>\u90a3\u4e48\u7528\u5e76\u67e5\u96c6\u5c31\u53ef\u4ee5\u641e\u5b9a\u4e86\u3002\u3002<br \/>\u8fd9\u4e2a\u7b97\u6cd5\u5b9e\u9645\u4e0a\u5c31\u662f\u79bb\u7ebfRMQ\u7684\u4e00\u79cd\u5e94\u7528\uff0c\u6211\u4ee5\u524d\u53d1\u8fc7\u8fd9\u6837\u90a3\u4e2a\u7b97\u6cd5\uff0c\u89c1\uff1a<a target=\"_blank\" href=\"http:\/\/hi.baidu.com\/wjbzbmr\/blog\/item\/b911be2c73f3385b4ec226fe.html\">\u4f20\u9001\u95e8<\/a><br \/>Code\uff1a<\/p>\n<p>#include&lt;cstdio&gt;<br \/>using namespace std;<br \/>const int maxn=200000;<br \/>int stack[maxn],top=0;<br \/>int F[maxn],A[maxn];<br \/>int find(int x){if(F[x]==x) return x; return F[x]=find(F[x]);}<br \/>void Union(int x,int y){F[y]=x;}<br \/>int main()<br \/>{<br \/>    \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin);<br \/>    int last=0,m,d,x,n=0;char c;<br \/>    scanf(&quot;%d %dn&quot;,&amp;m,&amp;d);<br \/>    while(m&#8211;)<br \/>    {<br \/>        scanf(&quot;%c %dn&quot;,&amp;c,&amp;x);<br \/>        if(c==&#8217;Q&#8217;)<br \/>            x=(n-x),printf(&quot;%dn&quot;,last=A[find(x)]);<br \/>        else<br \/>        {<br \/>            F[n]=n;A[n]=(last+x)%d;<br \/>            while(top&amp;&amp;A[stack[top-1]]&lt;=A[n])<br \/>                Union(n,stack[top-1]),top&#8211;;<br \/>            stack[top++]=n++;<br \/>        }<br \/>    }<br \/>}<\/p>\n<p>\u672c\u9ad8\u4eae\u4ee3\u7801\u4f7f\u7528codeHl\u751f\u6210\uff0c<a href=\"http:\/\/hi.baidu.com\/onlys_c\/blog\/item\/ef1149948c22d715d31b707e.html\" target=\"_blank\">\u67e5\u770b\u8be6\u60c5<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Link\uff1a61.187.179.132:8080\/JudgeOnline\/showproblem\u5c31\u662f\u8bf4\u8ba9\u4f60\u7ef4\u62a4\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u3002\u652f\u6301\u4e24\u4e2a\u64cd\u4f5c\uff0cA \u5728\u672b\u5c3e\u63d2\u5165\u4e00\u4e2a\u6570\uff0cQ L\uff0c\u6700\u540eL\u4e2a\u6570\u4e2d\u6700\u5927\u7684\u662f\u54ea\u4e2a\uff1f\u5f88\u660e\u663e\u8981\u7528\u5355\u8c03\u961f\u5217\u3002\u3002\u7528\u4e86\u5355\u8c03\u961f\u5217\u540e\u3002\u3002\u6574\u4e2a\u6570\u5217\u88ab\u5206\u6210\u51e0\u6bb5\u6bcf\u6bb5\u7684\u7b54\u6848\u90fd\u662f\u4e00\u6837\u7684\u3002\u3002\u90a3\u4e48\u5f04\u4e00\u4e2a\u5e76\u67e5\u96c6\u7ef4\u62a4\u7b54\u6848\u3002\u3002\u7136\u540e\u63d2\u5165\u4e00\u4e2a\u6570\u53ef\u80fd\u5bfc\u81f4\u51e0\u6bb5\u7684\u5408\u5e76\uff0c\u5c31\u6b63\u597d\u662f\u5e76\u67e5\u96c6\u7684Union\uff0c\u7136\u540e\u6bcf\u6bb5\u7684\u6839\u5c31\u662f\u8fd9\u6bb5\u7684\u7b54\u6848\u3002\u3002\u90a3\u4e48\u7528\u5e76\u67e5\u96c6\u5c31\u53ef\u4ee5\u641e\u5b9a\u4e86\u3002\u3002\u8fd9\u4e2a\u7b97\u6cd5\u5b9e\u9645\u4e0a\u5c31\u662f\u79bb\u7ebfRMQ\u7684\u4e00\u79cd\u5e94\u7528\uff0c\u6211\u4ee5\u524d\u53d1\u8fc7\u8fd9\u6837\u90a3\u4e2a\u7b97\u6cd5\uff0c\u89c1\uff1a\u4f20\u9001\u95e8Code\uff1a #include&lt;cstdio&gt;using namespace std;const int maxn=200000;int stack[maxn],top=0;int F[maxn],A[maxn];int find(int x){if(F[x]==x) return x; return F[x]=find(F[x]);}void Union(int x,int y){F[y]=x;}int main(){ \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin); int last=0,m,d,x,n=0;char c; scanf(&quot;%d %dn&quot;,&amp;m,&amp;d); while(m&#8211;) { scanf(&quot;%c %dn&quot;,&amp;c,&amp;x); if(c==&#8217;Q&#8217;) x=(n-x),printf(&quot;%dn&quot;,last=A[find(x)]); else { F[n]=n;A[n]=(last+x)%d; while(top&amp;&amp;A[stack[top-1]]&lt;=A[n]) Union(n,stack[top-1]),top&#8211;; stack[top++]=n++; } }} \u672c\u9ad8\u4eae\u4ee3\u7801\u4f7f\u7528codeHl\u751f\u6210\uff0c\u67e5\u770b\u8be6\u60c5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/132"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=132"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/132\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}