{"id":378,"date":"2017-03-03T16:52:37","date_gmt":"2017-03-03T08:52:37","guid":{"rendered":"http:\/\/kylelv.com\/?p=378"},"modified":"2017-12-28T14:47:21","modified_gmt":"2017-12-28T06:47:21","slug":"bzoj-3932-cqoi2015%e4%bb%bb%e5%8a%a1%e6%9f%a5%e8%af%a2%e7%b3%bb%e7%bb%9f-%e4%b8%bb%e5%b8%ad%e6%a0%91-%e6%9a%b4%e5%8a%9b","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=378","title":{"rendered":"bzoj 3932: [CQOI2015]\u4efb\u52a1\u67e5\u8be2\u7cfb\u7edf  &#8212; \u4e3b\u5e2d\u6811 \/ \u66b4\u529b"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdef43f1f69\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fdef43f1f69\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=378\/#3932_CQOI2015%E4%BB%BB%E5%8A%A1%E6%9F%A5%E8%AF%A2%E7%B3%BB%E7%BB%9F\" title=\"3932: [CQOI2015]\u4efb\u52a1\u67e5\u8be2\u7cfb\u7edf\">3932: [CQOI2015]\u4efb\u52a1\u67e5\u8be2\u7cfb\u7edf<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=378\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=378\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=378\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=378\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=378\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=378\/#HINT\" title=\"HINT\">HINT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.kylelv.com\/?p=378\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"3932_CQOI2015%E4%BB%BB%E5%8A%A1%E6%9F%A5%E8%AF%A2%E7%B3%BB%E7%BB%9F\"><\/span>3932: [CQOI2015]\u4efb\u52a1\u67e5\u8be2\u7cfb\u7edf<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a020 Sec\u00a0\u00a0Memory Limit:\u00a0512 MB<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\n<div>\u6700\u8fd1\u5b9e\u9a8c\u5ba4\u6b63\u5728\u4e3a\u5176\u7ba1\u7406\u7684\u8d85\u7ea7\u8ba1\u7b97\u673a\u7f16\u5236\u4e00\u5957\u4efb\u52a1\u7ba1\u7406\u7cfb\u7edf\uff0c\u800c\u4f60\u88ab\u5b89\u6392\u5b8c\u6210\u5176\u4e2d\u7684\u67e5\u8be2\u90e8\u5206\u3002\u8d85\u7ea7\u8ba1\u7b97\u673a\u4e2d\u7684\u4efb\u52a1\u7528\u4e09\u5143\u7ec4(Si,Ei,Pi)\u63cf\u8ff0\uff0c(Si,Ei,Pi)\u8868\u793a\u4efb\u52a1\u4ece\u7b2cSi\u79d2\u5f00\u59cb\uff0c\u5728\u7b2cEi\u79d2\u540e\u7ed3\u675f\uff08\u7b2cSi\u79d2\u548cEi\u79d2\u4efb\u52a1\u4e5f\u5728\u8fd0\u884c\uff09\uff0c\u4f18\u5148\u7ea7\u4e3aPi\u3002\u540c\u4e00\u65f6\u95f4\u53ef\u80fd\u6709\u591a\u4e2a\u4efb\u52a1\u540c\u65f6\u6267\u884c\uff0c\u5b83\u4eec\u7684\u4f18\u5148\u7ea7\u53ef\u80fd\u76f8\u540c\uff0c\u4e5f\u53ef\u80fd\u4e0d\u540c\u3002\u8c03\u5ea6\u7cfb\u7edf\u4f1a\u7ecf\u5e38\u5411\u67e5\u8be2\u7cfb\u7edf\u8be2\u95ee\uff0c\u7b2cXi\u79d2\u6b63\u5728\u8fd0\u884c\u7684\u4efb\u52a1\u4e2d\uff0c\u4f18\u5148\u7ea7\u6700\u5c0f\u7684Ki\u4e2a\u4efb\u52a1\uff08\u5373\u5c06\u4efb\u52a1\u6309\u7167\u4f18\u5148\u7ea7\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u540e\u53d6\u524dKi\u4e2a\uff09\u7684\u4f18\u5148\u7ea7\u4e4b\u548c\u662f\u591a\u5c11\u3002\u7279\u522b\u7684\uff0c\u5982\u679cKi\u5927\u4e8e\u7b2cXi\u79d2\u6b63\u5728\u8fd0\u884c\u7684\u4efb\u52a1\u603b\u6570\uff0c\u5219\u76f4\u63a5\u56de\u7b54\u7b2cXi\u79d2\u6b63\u5728\u8fd0\u884c\u7684\u4efb\u52a1\u4f18\u5148\u7ea7\u4e4b\u548c\u3002\u4e0a\u8ff0\u6240\u6709\u53c2\u6570\u5747\u4e3a\u6574\u6570\uff0c\u65f6\u95f4\u7684\u8303\u56f4\u57281\u5230n\u4e4b\u95f4\uff08\u5305\u542b1\u548cn\uff09\u3002<\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\n<div>\u8f93\u5165\u6587\u4ef6\u7b2c\u4e00\u884c\u5305\u542b\u4e24\u4e2a\u7a7a\u683c\u5206\u5f00\u7684\u6b63\u6574\u6570m\u548cn\uff0c\u5206\u522b\u8868\u793a\u4efb\u52a1\u603b\u6570\u548c\u65f6\u95f4\u8303\u56f4\u3002\u63a5\u4e0b\u6765m\u884c\uff0c\u6bcf\u884c\u5305\u542b\u4e09\u4e2a\u7a7a\u683c\u5206\u5f00\u7684\u6b63\u6574\u6570Si\u3001Ei\u548cPi(Si\u2264Ei)\uff0c\u63cf\u8ff0\u4e00\u4e2a\u4efb\u52a1\u3002\u63a5\u4e0b\u6765n\u884c\uff0c\u6bcf\u884c\u5305\u542b\u56db\u4e2a\u7a7a\u683c\u5206\u5f00\u7684\u6574\u6570Xi\u3001Ai\u3001Bi\u548cCi\uff0c\u63cf\u8ff0\u4e00\u6b21\u67e5\u8be2\u3002\u67e5\u8be2\u7684\u53c2\u6570Ki\u9700\u8981\u7531\u516c\u5f0f Ki=1+(Ai*Pre+Bi) mod Ci\u8ba1\u7b97\u5f97\u5230\u3002\u5176\u4e2dPre\u8868\u793a\u4e0a\u4e00\u6b21\u67e5\u8be2\u7684\u7ed3\u679c\uff0c\u5bf9\u4e8e\u7b2c\u4e00\u6b21\u67e5\u8be2\uff0cPre=1\u3002<\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\u8f93\u51fa\u5171n\u884c\uff0c\u6bcf\u884c\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u67e5\u8be2\u7ed3\u679c\u3002<\/div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">4 3<br \/>\n1 2 6<br \/>\n2 3 3<br \/>\n1 3 2<br \/>\n3 3 4<br \/>\n3 1 3 2<br \/>\n1 1 3 4<br \/>\n2 2 4 3<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">2<br \/>\n8<br \/>\n11<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>&nbsp;<\/p>\n<div>\u6837\u4f8b\u89e3\u91ca<\/div>\n<div>K1 = (1*1+3)%2+1 = 1<\/div>\n<div>K2 = (1*2+3)%4+1 = 2<\/div>\n<div>K3 = (2*8+4)%3+1 = 3<\/div>\n<div>\u5bf9\u4e8e100%\u7684\u6570\u636e\uff0c1\u2264m,n,Si,Ei,Ci\u2264100000\uff0c0\u2264Ai,Bi\u2264100000\uff0c1\u2264Pi\u226410000000\uff0cXi\u4e3a1\u5230n\u7684\u4e00\u4e2a\u6392\u5217<\/div>\n<div><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u597d\u4e0d\u5bb9\u6613\u6253\u5b8c\u4e86\u4e00\u4e2a\u4e3b\u5e2d\u6811\uff0c\u7136\u800c\u6709\u4eba\u8bf4\u76f4\u63a5\u66b4\u529b\u5c31\u884c\u3002\u3002What \uff1f\uff01 T_T<\/p>\n<p>\u597d\u5427\uff0c\u5c31\u5f53\u6211\u5728\u7ec3\u4e60\u4e3b\u5e2d\u6811\u597d\u4e86\u3002\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/1014417\/201703\/1014417-20170303164716266-1556686028.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/1014417\/201703\/1014417-20170303164741329-1059976978.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u601d\u8def1\uff1a \u4e3b\u5e2d\u6811<\/p>\n<p>\u4ee5\u65f6\u523b\u4e3a\u4e0b\u6807\uff0c\u4f18\u5148\u7ea7\u4e3a\u533a\u95f4\u5efa\u4e3b\u5e2d\u6811\u3002\u5bf9\u4e8e\u5728\u4e00\u4e2a\u533a\u95f4[l,r]\u5185\u5b58\u5728\u7684\u4efb\u52a1\uff0c\u53ef\u5dee\u5206\u5904\u7406\uff0c\u62c6\u6210\u4e24\u4e2a\u70b9\uff0c\u5728l\u5904\u51fa\u73b0\u6b21\u6570\u52a01\uff0c\u5728r+1\u5904\u51fa\u73b0\u6b21\u6570\u51cf1\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\n#include&lt;iostream&gt;\r\n#include&lt;algorithm&gt;\r\nusing namespace std;\r\n#define ll long long\r\n#define N 200010\r\n#define M 10000010\r\ninline ll read()\r\n{\r\n    ll x=0,f=1;char ch=getchar();\r\n    while(ch&lt;'0'||ch&gt;'9'){if(ch=='-')f=-1;ch=getchar();}\r\n    while(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n    return x*f;\r\n}\r\nll sum[M];\r\nint ls[M],rs[M],rt[M],w[M],lim,cnt,to[M];\r\ninline void add(int l,int r,int x,int &amp;y,int v)\r\n{\r\n    y=++cnt;\r\n    w[y]=w[x]+(v&gt;0?1:-1);\r\n    sum[y]=sum[x]+v;\r\n    if(l==r) return;\r\n    ls[y]=ls[x];rs[y]=rs[x];\r\n    int mid=(l+r)&gt;&gt;1;\r\n    if(abs(v)&gt;mid) add(mid+1,r,rs[x],rs[y],v);\r\n    else add(l,mid,ls[x],ls[y],v);\r\n}\r\nll que(int t,int k)\r\n{\r\n    int x=rt[t],l=1,r=lim,mid;\r\n    if(w[x]&lt;=k) return sum[x];\r\n    ll ans=0;\r\n    while(l&lt;r)\r\n    {\r\n        mid=(l+r)&gt;&gt;1;\r\n        if(w[ls[x]]&gt;=k)\r\n        {\r\n            x=ls[x];\r\n            r=mid;\r\n        }\r\n        else \r\n        {\r\n            k-=w[ls[x]];\r\n            ans+=sum[ls[x]];\r\n            x=rs[x];\r\n            l=mid+1;\r\n        }\r\n    }\r\n    if(k) ans+=(ll)(l)*(ll)(k);\r\n    return ans;\r\n}\r\nstruct qaz{int t,p;}q[N];\r\ninline bool cmp(qaz a,qaz b){return a.t&lt;b.t;}\r\nint m,n,s,e,tp;\r\nll x,a,b,c,pre=1,k;\r\nint main()\r\n{\r\n    m=read();n=read();\r\n    for(int i=1;i&lt;=m;i++)\r\n    {\r\n        s=read();e=read();tp=read();\r\n        lim=max(lim,tp);\r\n        q[i].t=s;q[i].p=tp;\r\n        q[i+m].t=e+1;q[i+m].p=-tp;;\r\n    }\r\n    m&lt;&lt;=1;\r\n    sort(q+1,q+m+1,cmp);\r\n    for(int i=1;i&lt;=m;i++) add(1,lim,rt[i-1],rt[i],q[i].p);\r\n    for(int i=m;i&gt;0;i--) if(q[i].t!=q[i+1].t) to[q[i].t]=i;\r\n    for(int i=1;i&lt;=n;i++) if(!to[i]) to[i]=to[i-1];\r\n    for(int i=0;i&lt;n;i++)\r\n    {\r\n        x=read();a=read();b=read();c=read();\r\n        k=(a*pre+b)%c;\r\n        k++;\r\n        pre=que(to[x],k);\r\n        printf(\"%lld\\n\",pre);\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\u601d\u8def2\uff1a\u66b4\u529b\u3002\u3002\u3002<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\n#include&lt;algorithm&gt;\r\n#define M 100010\r\n#define ll long long\r\nint n,m,x,a,b,c,k;\r\nll pre=1;\r\nstruct qaz{int s,e,p;}D[M];\r\nbool cmp(qaz a,qaz b){return a.p&lt;b.p;}\r\nint main()\r\n{\r\n    scanf(\"%d%d\",&amp;m,&amp;n);\r\n    for(int i=1;i&lt;=m;i++) scanf(\"%d%d%d\",&amp;D[i].s,&amp;D[i].e,&amp;D[i].p);\r\n    std::sort(1+D,1+m+D,cmp);\r\n    while(n--)\r\n    {\r\n        scanf(\"%d%d%d%d\",&amp;x,&amp;a,&amp;b,&amp;c);\r\n        k=1+(a*pre%c+b)%c;pre=0;\r\n        int d=0;\r\n        for(int i=1;i&lt;=m&amp;&amp;d&lt;k;i++)\r\n            if(D[i].s&lt;=x&amp;&amp;D[i].e&gt;=x){pre+=D[i].p;d++;}\r\n        printf(\"%lld\\n\",pre);\r\n    }\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 3932: [CQOI2015]\u4efb\u52a1\u67e5\u8be2\u7cfb\u7edf Time Limit:\u00a020 Sec\u00a0\u00a0Memor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[35],"class_list":["post-378","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-35"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=378"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":380,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions\/380"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}