{"id":347,"date":"2018-07-30T15:35:53","date_gmt":"2018-07-30T15:35:53","guid":{"rendered":"https:\/\/www.haoyuan.info\/?p=347"},"modified":"2018-07-30T15:35:53","modified_gmt":"2018-07-30T15:35:53","slug":"hdu6319-2018hdu%e5%a4%9a%e6%a0%a1%e7%ac%ac%e4%b8%89%e5%9c%ba-1001-problem-a-ascending-rating","status":"publish","type":"post","link":"https:\/\/haoyuan.info\/?p=347","title":{"rendered":"HDU6319 2018HDU\u591a\u6821\u7b2c\u4e09\u573a 1001 Problem A. Ascending Rating"},"content":{"rendered":"<p>\u9898\u610f\u7565<\/p>\n<p>coding\u51fa\u6765\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u6309\u7167\u9898\u76ee\u8981\u6c42\u586b\u5199\u6570\u7ec4\uff0c\u7136\u540e\u5012\u7740\u641c\u7ef4\u62a4\u4e00\u4e2a\u5355\u8c03\u961f\u5217\u5c31\u53ef\u4ee5\u4e86\uff0c\u7ef4\u62a4\u5355\u8c03\u961f\u5217\u7684\u65f6\u5019\u8981\u6ce8\u610f\u5355\u8c03\u961f\u5217\u4e2d\u5143\u7d20\u6570\u91cf\u7b49\u4ef7\u4e8e\u76ee\u6807\u533a\u95f4$$count_i$$\u7684\u503c\uff0c\u5373$$count_i = q.size()$$<br \/>\nAC\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\" line-numbers\">#include &lt;iostream&gt;\n#include &lt;queue&gt;\n#include &lt;algorithm&gt;\n#include &lt;array&gt;\n\nusing namespace std;\nusing ll = long long;\nconst int maxn = 1e7 + 1e2;\narray&lt;int, maxn&gt; a;\nint n, m, k, P, Q, R, mod;\nll A, B;\ndeque&lt;int&gt; q;\n\nint main() {\n    ios::sync_with_stdio(false);\n    cin.tie(0);\n    cout.tie(0);\n    int T;\n    cin &gt;&gt; T;\n    while (T--) {\n        q.clear();\n        cin &gt;&gt; n &gt;&gt; m &gt;&gt; k &gt;&gt; P &gt;&gt; Q &gt;&gt; R &gt;&gt; mod;\n        for (int i = 1; i &lt;= k; ++i)cin &gt;&gt; a[i];\n        for (int i = k + 1; i &lt;= n; ++i) {\n            a[i] = (1ll * P * a[i - 1] + 1ll * Q * i + R) % mod;\n        }\n        A = B = 0;\n        for (int i = n; i; --i) {\n            while (!q.empty() &amp;&amp; a[q.back()] &lt;= a[i])q.pop_back();\/\/\u7ef4\u62a4\u5355\u8c03\u961f\u5217\n            q.push_back(i);\/\/\u6ce8\u610f\uff0c\u8fd9\u4e2a\u961f\u5217\u662f\u4fdd\u8bc1\u961f\u5c3e\u5143\u7d20\u6700\u5c0f\u7684 \u6240\u4ee5\u8981\u63d2\u5165\u7684\u503c\u82e5\u6bd4\u961f\u5c3e\u5143\u7d20\u5927\n                           \/\/\u4e00\u5b9a\u8981\u53bb\u9664\u5bf9\u7b54\u6848\u6ca1\u6709\u8d21\u732e\u7684\u5143\u7d20 \u8fd9\u4e2a\u662f\u5173\u952e\n            if (i + m - 1 &lt;= n) {\/\/\u5f53\u533a\u95f4\u5927\u5c0f\u6ee1\u8db3\u9898\u610f\u8981\u6c42\n                while (q.front() &gt;= i + m) q.pop_front();\/\/\u8fd9\u91cc\u6e05\u9664\u7684\u662f\u4e0d\u6ee1\u8db3\u5f53\u524d\u6240\u53d6\u533a\u95f4\u8303\u56f4\u7684\u503c\n                A += i ^ a[q.front()];\n                B += i ^ q.size();\n            }\n        }\n        cout &lt;&lt; A &lt;&lt; \" \" &lt;&lt; B &lt;&lt; \"\\n\";\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u610f\u7565 coding\u51fa\u6765\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u6309\u7167\u9898\u76ee\u8981\u6c42\u586b\u5199\u6570\u7ec4\uff0c\u7136\u540e\u5012\u7740\u641c\u7ef4\u62a4\u4e00\u4e2a\u5355\u8c03\u961f\u5217\u5c31\u53ef\u4ee5\u4e86\uff0c\u7ef4\u62a4\u5355\u8c03\u961f\u5217\u7684\u65f6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[39,22,45],"tags":[],"class_list":["post-347","post","type-post","status-publish","format-standard","hentry","category-c","category-22","category-45"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8UC2c-5B","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347"}],"version-history":[{"count":1,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/347\/revisions"}],"predecessor-version":[{"id":348,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/347\/revisions\/348"}],"wp:attachment":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}