{"id":344,"date":"2022-08-23T01:13:57","date_gmt":"2022-08-22T17:13:57","guid":{"rendered":"https:\/\/blog.cirno.fun\/?p=344"},"modified":"2024-09-12T09:35:46","modified_gmt":"2024-09-12T01:35:46","slug":"%e7%bb%8f%e5%85%b8%e8%80%81%e7%95%aa-%e5%8d%95%e8%b0%83%e9%98%9f%e5%88%97%e5%92%8c%e6%bb%91%e5%8a%a8%e7%aa%97%e5%8f%a3%e6%9c%80%e5%a4%a7%e5%80%bc","status":"publish","type":"post","link":"https:\/\/blog.sssn.tech\/?p=344","title":{"rendered":"\u7ecf\u5178\u8001\u756a\u2014\u2014\u5355\u8c03\u961f\u5217\u548c\u6ed1\u52a8\u7a97\u53e3\u6700\u5927\u503c"},"content":{"rendered":"<p>\u8fd9\u9898\u9ad8\u4e2d\u5c31\u505a\u4e86\u4e24\u904d\uff0c\u611f\u89c9\u7406\u89e3\u4e0d\u662f\u5f88\u900f\u5f7b\uff0c\u4eca\u5929\u53c8\u505a\u5230\u8fd9\u9898\uff0c\u5199\u4e00\u7bc7\u9898\u89e3\u6765\u52a0\u6df1\u5370\u8c61 \u770b\u9898\uff1a <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661186829137.png\" alt=\"file\" \/><img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661186847619.png\" alt=\"file\" \/>\u9898\u610f\u4e0d\u96be\uff0c\u73b0\u5728\u6211\u6765\u8fd8\u539f\u4e00\u4e0b\u8fd9\u9898\u5e94\u6709\u7684\u5b8c\u6574\u601d\u8003\u8fc7\u7a0b\uff1a \u672c\u9898\u662f\u8981\u6c42\u4e00\u4e2a\u5927\u533a\u95f4N\u7684\u6bcf\u4e00\u4e2a\u8fde\u7eed\u5b50\u533a\u95f4k\u7684\u6781\u5927\uff08\u6781\u5c0f\uff09\u503c\uff0c\u4e3a\u65b9\u4fbf\u7406\u89e3\uff0c\u5148\u8003\u8651\u6700\u5927\u503c\u60c5\u51b5<\/p>\n<p>\u4e00\u4e2a\u5f88\u81ea\u7136\u7684\u60f3\u6cd5\u4fbf\u662f\u679a\u4e3e\u6bcf\u4e00\u4e2a\u533a\u95f4\uff0c\u53ef\u4ee5\u4ee4i\u4ece1\u5f00\u59cb\uff0c\u5230n-k\u7ed3\u675f\uff0c\u5728\u5b50\u5faa\u73af\u91cc\u7528j\u679a\u4e3e\u533a\u95f4\u5143\u7d20\uff0c\u6bcf\u6b21k\u90fd\u9700\u8981\u4ece\u5de6\u81f3\u53f3\u626b\u63cf\uff0c\u7136\u540e\u66f4\u65b0\u51fa\u6700\u5927\u503c<\/p>\n<p>\u8fd9\u4e2a\u6734\u7d20\u505a\u6cd5\u6b63\u786e\u6027\u6ca1\u95ee\u9898\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u663e\u7136\u662f<code>Nk<\/code>\uff0c\u53c8\u56e0\u4e3a<code>k\uff0c\u6700\u5dee\u65f6\u95f4\u4fbf\u662f<\/code>N^2<code>\u672c\u9898\u4e2d<\/code>N\uff0c\u9700\u8981\u4f18\u5316\u81f3<code>NlogN<\/code>\u6216\u4ee5\u4e0b\u7ea7\u522b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u719f\u6089\u66b4\u529b\u505a\u6cd5\u540e\uff0c\u6211\u4eec\u6765\u8003\u8651\u4f18\u5316\u95ee\u9898\uff1a&#8220;<\/p>\n<p>\u6211\u4eec\u7528\u4e00\u4e2a\u961f\u5217q\u6765\u7ef4\u62a4<strong>\u5f53\u524d\u6240\u5728\u7684\u533a\u95f4<\/strong>\uff0c\u5f53\u7a97\u53e3\u5411\u53f3\u6ed1\u52a8\u65f6\uff0c\u5de6\u4fa7\u5143\u7d20\u51fa\u961f\uff0c\u53f3\u4fa7\u5143\u7d20\u5165\u961f\uff0c\u4e3a\u4e86\u4fbf\u4e8e\u7406\u89e3\uff0c\u6211\u4eec\u89c4\u5b9a\u5de6\u4fa7\u662f\u5934\uff0c\u53f3\u4fa7\u662f\u5c3e<\/p>\n<p>\u800c\u5f53\u4e00\u4e2a\u5143\u7d20a[i]\u8fdb\u5165\u8fd9\u4e2a\u7a97\u53e3\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff1a<strong>\u4ece\u533a\u95f4\u5934\u5f00\u59cb\uff0c\u5230a[i]\u7ed3\u675f\uff0c\u4efb\u4f55\u6bd4a[i]\u5c0f\u7684\u5143\u7d20\u90fd\u4e0d\u4f1a\u6210\u4e3a\u73b0\u5728\u95ee\u9898\u7684\u7b54\u6848\uff0c\u4e5f\u4e0d\u4f1a\u6210\u4e3a\u63a5\u4e0b\u6765\u95ee\u9898\u7684\u7b54\u6848<\/strong><\/p>\n<p>\u8fd9\u53e5\u8bdd\u6709\u70b9\u7ed5\uff0c\u4f46\u662f\u8bf7\u7406\u89e3\u4e00\u4e0b\uff0c\u6211\u4e3e\u4e2a\u4f8b\u5b50\uff1a \u5047\u8bbe\u6211\u4eec\u6240\u5728\u4e00\u4e2ak=5\u7684\u533a\u95f4\uff0c\u533a\u95f4\u5143\u7d20\u5206\u522b\u662f10,9,8,4,3,2\u2014\u2014\u73b0\u5728\u7684\u7b54\u6848\u663e\u7136\u662f10\uff0c\u7136\u540e\u7a97\u53e3\u5411\u53f3\u6ed1\u52a8\uff0c10\u51fa\u961f\uff0c\u5047\u8bbe\u65b0\u5165\u961f\u5143\u7d20\u662f6,\u73b0\u5728\u7a97\u53e3\u5185\u7684\u5143\u7d20\u662f9,8,4,3,2,6<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u5f536\u8fdb\u5165\u5230\u8fd9\u4e2a\u7a97\u53e3\u65f6\uff0c\u6bd46\u5c0f\u76844,3,2<strong>\u4e0d\u518d\u53ef\u80fd\u6210\u4e3a\u7b54\u6848\uff0c\u56e0\u4e3a\u4ece\u73b0\u5728\u5f00\u59cb\u7a97\u53e3\u5411\u53f3\u6ed1\u52a8\u7684\u8fc7\u7a0b\u4e2d\uff0c\u7b54\u6848\u81f3\u5c11\u662f6\uff0c\u6216\u8005\u6bd46\u5927<\/strong><\/p>\n<p>\u8fd9\u4fbf\u662f\u8fd9\u9053\u9898\u7684\u601d\u60f3\uff1a\u7ef4\u62a4\u4e00\u4e2a\u5355\u8c03\u7684\u961f\u5217\uff0c\u63a7\u5236\u7a97\u53e3\u5185\u7684\u6700\u5927\u503c\u603b\u5728\u961f\u5934\uff0c\u5f53\u6709\u65b0\u5143\u7d20\u8fdb\u5165\u7a97\u53e3\u65f6\uff0c\u4ece\u961f\u5c3e\u5f39\u51fa\u4e0d\u7b26\u5408\u8981\u6c42\u7684\u5143\u7d20\uff08\u56e0\u4e3a\u4ed6\u4eec\u4e0d\u4f1a\u6210\u4e3a\u7b54\u6848\uff09\uff0c\u6765\u7ef4\u62a4\u961f\u5217\u7684\u5355\u8c03\u6027\uff0c\u6bcf\u6b21\u67e5\u8be2\u65f6\uff0c\u53ea\u9700\u8f93\u51fa\u961f\u5934\u7684\u6700\u5927\u503c\u5373\u53ef<\/p>\n<p>\u4e0a\u9762\u8bf4\u7684\u8fd8\u662f\u6bd4\u8f83\u62bd\u8c61\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661188782174.png\" alt=\"file\" \/>\u8fd9\u662f\u672c\u9898\u7684\u6837\u4f8b\uff0c\u73b0\u5728k=3\u7684\u7a97\u53e3\u4ece\u5de6\u4fa7\u5f00\u59cb\u6ed1\u52a8 <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661188884362.png\" alt=\"file\" \/><\/p>\n<p>\u6b64\u65f6\u961f\u5217\u91cc\u53ea\u6709\u4e00\u4e2a\u5143\u7d201\uff0c\u73b0\u5728\u7a97\u53e3\u7ee7\u7eed\u6ed1\u52a8 <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661189123923.png\" alt=\"file\" \/>\u6ce8\u610f\uff01\u73b0\u5728\u5143\u7d203\u8981\u8fdb\u5165\u961f\u5217\uff0c\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\uff0c\u56e0\u4e3a<code>1\uff0c\u6240\u4ee5\u4eca\u540e\u7684\u4efb\u4f55\u65f6\u523b\uff0c1\u90fd\u4e0d\u53ef\u80fd\u6210\u4e3a\u7b54\u6848\uff0c\u6211\u4eec\u5c061\u51fa\u961f\uff0c\u8ba93\u5165\u961f&lt;img alt=&quot;file&quot; src=&quot;https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661189221183.png&quot;&gt;&lt;\/img&gt;<\/code><\/p>\n<p>\u7a97\u53e3\u7ee7\u7eed\u6ed1\u52a8\u2014\u2014\u961f\u5217\u91cc\u52a0\u5165-1\uff0c\u6211\u4eec\u8ba9-1\u5165\u961f\u5373\u53ef \u73b0\u5728\u961f\u5934\u5143\u7d20\u4fbf\u662f\u7b2c\u4e00\u4e2a\u7b54\u6848\u2014\u20143<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661189333875.png\" alt=\"file\" \/><\/p>\n<p>\u63a5\u4e0b\u6765\u7a97\u53e3\u7ee7\u7eed\u5411\u53f3\u6ed1\u52a8\uff0c\u6b64\u65f6\u5982\u679c1\u8fd8\u5728\u961f\u5217\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5c06\u4ed6\u51fa\u961f\uff0c\u4e0d\u8fc7\u6b64\u65f6\u4ed6\u5df2\u7ecf\u4e0d\u5728\u4e86 -3\u5165\u961f\u540e\u961f\u5217\u4f9d\u65e7\u5355\u8c03\uff0c\u6b64\u65f6\u961f\u5934\u662f\u7b2c\u4e8c\u4e2a\u7b54\u68483 <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661189510400.png\" alt=\"file\" \/>\u73b0\u5728\u7a97\u53e3\u518d\u6b21\u6ed1\u52a8\uff0c\u65b0\u7684\u5143\u7d20\u662f5\uff0c\u6b64\u65f6\u961f\u5217\u4e2d\u6bd45\u5c0f\u7684\u76843\uff0c-1\uff0c-3\u90fd\u4e0d\u53ef\u80fd\u6210\u4e3a\u7b54\u6848\u4e86\uff0c\u6211\u4eec\u5168\u90e8\u5f39\u51fa\uff0c\u5c065\u5165\u961f\uff0c\u5e76\u4e14\u6253\u5370\u7b54\u68485 <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661189615761.png\" alt=\"file\" \/>\u5269\u4f59\u6ed1\u52a8\u540c\u7406\uff1a <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661189716924.png\" alt=\"file\" \/><img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661189752419.png\" alt=\"file\" \/><img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1661189795733.png\" alt=\"file\" \/>\u5982\u679c\u8fd8\u6ca1\u6709\u7406\u89e3\uff0c\u5efa\u8bae\u624b\u63a8\u4e00\u904d\u4e0a\u9762\u7684\u8fc7\u7a0b<\/p>\n<p>\u4e0b\u9762\u662f\u4ee3\u7801<\/p>\n<pre><code class=\"language-cpp\">#include&lt;bits\/stdc++.h&gt;\n#define P system(&quot;pause&quot;)\n#define E puts(&quot;&quot;)\nusing namespace std;\ntypedef long long ll;\n\nconst int N=5e5+10;\nint a[N],q[N],head=1,tail=0;\n\/\/\u4e3a\u4e86\u65b9\u4fbf\u5224\u65ad\u961f\u5934\u7684\u4f4d\u7f6e\uff0c\u6211\u4eec\u7684\u961f\u5217\u4e0d\u50a8\u5b58\u5143\u7d20\u7684\u5177\u4f53\u503c\uff0c\u5b58\u5143\u7d20\u5728\u6570\u7ec4a[]\u4e2d\u7684\u4f4d\u7f6e\uff08\u4e0b\u6807\uff09\nvoid initq(){\n    head=1;tail=0;\n}\n\nint main(){\n    \/\/ios::sync_with_stdio(false);\n    int n,k;\n    scanf(&quot;%d%d&quot;,&amp;n,&amp;k);\n    for(int i=1;i&lt;=n;i++)\n        scanf(&quot;%d&quot;,&amp;a[i]);\n    initq();\/\/\u521d\u59cb\u5316\u961f\u5217\n    for(int i=1;i&lt;=n;i++){\/\/\u6ce8\u610f\uff0c\u73b0\u5728\u5728\u7ef4\u62a4\u533a\u95f4\u6700\u5c0f\u503c\uff0c\u6240\u4ee5\u7b54\u6848\u603b\u662f\u5c0f\u7684\u5728\u524d\uff0c\u961f\u5217\u662f\u5355\u8c03\u9012\u589e\u7684\n        if(head&lt;=tail &amp;&amp; i-q[head]&gt;=k)\n            head++;\/\/\u5f53\u961f\u4f0d\u4e0d\u4e3a\u7a7a\u4e14\u7a97\u53e3\u5de6\u4fa7\u5212\u8fc7\u961f\u5934\u6240\u5728\u4f4d\u7f6e\u65f6\uff0c\u961f\u5934\u51fa\u961f\n        while(head&lt;=tail &amp;&amp; a[q[tail]]&gt;=a[i])\n            tail--; \/\/\u5f53\u961f\u4f0d\u4e0d\u4e3a\u7a7a\u4e14\u961f\u5c3e\u5143\u7d20\u5927\u4e8e\u5f53\u524d\u5143\u7d20\uff0c\u8bf4\u660e\u8fd9\u4e2a\u5143\u7d20\u4e0d\u53ef\u80fd\u6210\u4e3a\u7b54\u6848\u4e86\uff0c\u51fa\u961f\n        q[++tail]=i;\/\/\u5f53\u524d\u5143\u7d20\u5165\u961f\n        if(i&lt;k)\/\/\u5904\u7406\u7a97\u53e3\u8fd8\u6ca1\u8fdb\u5165\u533a\u95f4\u7684\u60c5\u51b5\uff0c\u5373\u4e0a\u9762\u6700\u5f00\u59cb\u7684\u4e24\u5f20\u56fe\uff0c\u6b64\u65f6\u53ea\u7ef4\u62a4\u961f\u5217\uff0c\u4e0d\u8f93\u51fa\u7b54\u6848\n            continue;\n        printf(&quot;%d &quot;,a[q[head]]);\n    }\n    E;\n    initq();\n    for(int i=1;i&lt;=n;i++){\/\/\u5b8c\u5168\u76f8\u540c\n        if(head&lt;=tail &amp;&amp; i-q[head]&gt;=k)\n            head++;\n        while(head&lt;=tail &amp;&amp; a[q[tail]]&lt;=a[i])\n            tail--;\n        q[++tail]=i;\n        if(i&lt;k)\n            continue;\n        printf(&quot;%d &quot;,a[q[head]]);\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u9898\u9ad8\u4e2d\u5c31\u505a\u4e86\u4e24\u904d\uff0c\u611f\u89c9\u7406\u89e3\u4e0d\u662f\u5f88\u900f\u5f7b\uff0c\u4eca\u5929\u53c8\u505a\u5230\u8fd9\u9898\uff0c\u5199\u4e00\u7bc7\u9898\u89e3\u6765\u52a0\u6df1\u5370\u8c61 \u770b [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-344","post","type-post","status-publish","format-standard","hentry","category-13"],"_links":{"self":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=344"}],"version-history":[{"count":1,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/344\/revisions"}],"predecessor-version":[{"id":752,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/344\/revisions\/752"}],"wp:attachment":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}