{"id":1234,"date":"2024-08-30T18:34:00","date_gmt":"2024-08-30T10:34:00","guid":{"rendered":"https:\/\/diary.bid\/?p=1234"},"modified":"2025-08-30T18:34:46","modified_gmt":"2025-08-30T10:34:46","slug":"%e7%ac%ac%e4%b8%80%e7%ab%a0-%e5%9f%ba%e7%a1%80%e7%ae%97%e6%b3%95%ef%bc%88%e4%b8%89%ef%bc%89","status":"publish","type":"post","link":"https:\/\/diary.bid\/?p=1234","title":{"rendered":"\u7b2c\u4e00\u7ae0 \u57fa\u7840\u7b97\u6cd5\uff08\u4e09\uff09"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u672c\u8282\u4e3b\u8981\u5b66\u4e60\u53cc\u6307\u9488\u3001\u4f4d\u8fd0\u7b97\u3001\u79bb\u6563\u5316\u3001\u533a\u95f4\u5408\u5e76\u7b49\u77e5\u8bc6\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-0\">\u53cc\u6307\u9488\u7b97\u6cd5<\/h2>\n\n\n\n<p>\u5e38\u89c1\u7c7b\u578b\uff1a\u6307\u5411\u4e24\u4e2a\u4e0d\u540c\u5e8f\u5217 \u6216\u8005 \u6307\u5411\u540c\u4e00\u4e2a\u7cfb\u5217\u7684\u4e0d\u540c\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250731213418888.png\" alt=\"image-20250731213418888\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-1\">\u901a\u7528\u6a21\u7248<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >for(i = 0, j =0; i &lt; n; i++){\n    while(j&lt;i &amp;&amp; check(i,j)) j++;\n    \/\/\u6bcf\u9053\u9898\u76ee\u7684\u5177\u4f53\u903b\u8f91\n}<\/code><\/pre>\n\n\n\n<p><strong>\u6838\u5fc3\u601d\u60f3\uff1a<\/strong>\u5c06\u4e0b\u9762\u7684\u6734\u7d20\u7b97\u6cd5\u4f18\u5316\u5230 $O(n)$ \u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >for(int i = 0; i &lt; n; i++){\n    for (int j = 0; j &lt; n; j ++){\n\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>\u4e3e\u4f8b\uff1a<\/strong>\u4e00\u4e32\u5b57\u7b26\u4e32\u91cc\u9762\u5355\u8bcd\u7528\u7a7a\u683c\u5206\u9694\uff0c\u7528\u53cc\u6307\u9488\u628a\u6bcf\u4e2a\u5355\u8bcd\u90fd\u5f04\u51fa\u6765\u3002<\/p>\n\n\n\n<p><strong>\u4e3e\u4f8b2\uff1a<\/strong>\u7ed9\u5b9a\u6574\u6570\u5e8f\u5217\uff0c\u6c42\u6700\u957f\u65e0\u91cd\u590d\u6570\u5b57\u7684\u8fde\u7eed\u5b50\u5e8f\u5217\u957f\u5ea6\u3002<\/p>\n\n\n\n<p>\u505a\u6cd5\uff1a\u7528\u6307\u9488<code class=\"prettyprint linenums\" >i<\/code>\u679a\u4e3e\u53f3\u7aef\u70b9\uff0c\u6307\u9488<code class=\"prettyprint linenums\" >j<\/code>\u7ef4\u62a4\u6700\u8fdc\u5de6\u7aef\u70b9\uff0c\u7528\u54c8\u5e0c\u8868\u8bb0\u5f55\u533a\u95f4\u5185\u6bcf\u4e2a\u5143\u7d20\u7684\u51fa\u73b0\u6b21\u6570\uff0c\u603b\u5171\u5faa\u73af\u6b21\u6570<code class=\"prettyprint linenums\" >2n<\/code>\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u964d\u4f4e\u5230\u4e86 $O(n)$ \u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >for (int i = 0, j = 0; i &lt; n; i++){\n    while(j &lt; i &amp;&amp; check(i,j)){\n        pop(arr&#091;j]);\n        j++;\n    }\n    res = max(res,i-j+1);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-2\">\u5e38\u7528\u4f4d\u8fd0\u7b97<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6c42n\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u7b2ck\u4f4d\u662f\u51e0\uff08\u8bb0\u4e2a\u4f4d\u662f0\u4f4d\uff09<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >   n &gt;&gt; k &amp; 1<\/code><\/pre>\n\n\n\n<p><strong>\u4f5c\u7528\uff1a<\/strong>\u8f93\u51fan\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u3002<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u8fd4\u56dex\u7684\u6700\u540e\u4e00\u4f4d1\uff0c\u5982101000->1000<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >   x &amp; -x = x &amp; (~x + 1)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250803195403715.png\" alt=\"image-20250803195403715\"\/><\/figure>\n\n\n\n<p><strong>\u4f5c\u7528\uff1a<\/strong>\u6c42n\u7684\u4e8c\u8fdb\u5236\u8868\u8fbe\u4e2d\u76841\u7684\u4e2a\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-3\">\u79bb\u6563\u5316<\/h2>\n\n\n\n<p>\u6574\u6570\u3001\u6709\u5e8f\u7684\u79bb\u6563\u5316\u3002\u6bd4\u5982\u4e00\u4e2a\u6570\u7ec4\u503c\u57df\u4e3a$(0,10^9)$\uff0c\u4e2a\u6570\u4e3a$10^5$\u3002\u6b64\u65f6\u5982\u679c\u60f3\u628a\u6570\u7ec4\u503c\u8f6c\u5316\u4e3a\u4e0b\u6807\u4f7f\u7528\uff0c\u6b64\u65f6\u9700\u8981\u8fdb\u884c\u6620\u5c04\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u79f0\u4f5c\u79bb\u6563\u5316\u3002<\/p>\n\n\n\n<p>\u79bb\u6563\u5316\u53ef\u80fd\u7528\u4e24\u4e2a\u95ee\u9898\uff1a1. <code class=\"prettyprint linenums\" >a[]<\/code>\u4e2d\u53ef\u80fd\u6709\u91cd\u590d\u5143\u7d20\uff0c\u9700\u8981\u53bb\u91cd\uff1b2.\u5982\u4f55\u7b97\u51fa<code class=\"prettyprint linenums\" >a[i]<\/code>\u79bb\u6563\u5316\u540e\u7684\u503c\u662f\u591a\u5c11\u3002<\/p>\n\n\n\n<p><strong>\u89e3\u51b3\u529e\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<p>\u5148\u628a\u6240\u6709\u503c\u7528sort\u6392\u5e8f\uff0c\u518d\u7528<code class=\"prettyprint linenums\" >arr.erase(unique(arr.begin(),arr.end()),arr.end())<\/code>\u53bb\u9664\u91cd\u590d\u5143\u7d20\uff0c\u518d\u4f7f\u7528\u4e8c\u5206\u67e5\u627e\u67e5\u51fa\u6765\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >\/\/\u624b\u52a8\u5b9e\u73b0unique\u51fd\u6570\nvector&lt;int&gt;::iterator unique(vector&lt;int&gt; &amp;a){\n    int j = 0;\n    for(int i = 0; i &lt; a.size(); i ++){\n        if(!i || a&#091;i] != a&#091;i-1]) a&#091;j++] = a&#091;i];\n    }\n    return a.bigin() + j;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-4\">\u533a\u95f4\u5408\u5e76<\/h2>\n\n\n\n<p>\u7ed9\u5b9an\u4e2a\u533a\u95f4 $[l_i, r_i]$ \uff0c\u8981\u6c42\u5408\u5e76\u6240\u6709\u6709\u4ea4\u96c6\u7684\u533a\u95f4\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6309\u533a\u95f4\u5de6\u7aef\u70b9\u6392\u5e8f\u3002<\/li>\n\n\n\n<li>\u6309\u5de6\u7aef\u70b9\u4ece\u5c0f\u5230\u5927\u987a\u5e8f\u904d\u5386\uff0c\u8bb0\u5f55\u4e00\u4e2a\u5f53\u524d\u7684\u533a\u95f4\uff0c\u626b\u63cf\u63a5\u4e0b\u6765\u7684\u533a\u95f4\u662f\u5426\u4e0e\u5f53\u524d\u533a\u95f4\u6709\u4ea4\u96c6\uff0c\u82e5\u6709\u4ea4\u96c6\u5219\u5408\u5e76\u5728\u4e00\u8d77\u5e76\u7ee7\u7eed\u626b\u63cf\uff0c\u5982\u679c\u6ca1\u6709\u4ea4\u96c6\u5c31\u628a\u5f53\u524d\u533a\u95f4\u66f4\u65b0\u4e3a\u8fd9\u4e2a\u533a\u95f4\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >void merge(vector&lt;PII&gt; &amp;segs){\n    vector&lt;PII&gt; res;\n    sort(segs.begin(), segs.end());\n    int st = -2e9, ed = -2e9;\n    for(auto seg: segs){\n        if(ed &lt; seg.first){\n            if (st != -2e9) res.push_back({st,ed});\n            st = seg.first, ed = seg.second;\n        }\n        else ed = max(ed,seg.second);\n    }\n    if(st != -2e9) res.push_back({st,ed});\n    segs = res;\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n<div class=\"comment--location\"><svg version=\"1.1\" viewBox=\"0 0 368.666 368.666\"  width=\"14\" height=\"14\"><g><path d=\"M184.333,0C102.01,0,35.036,66.974,35.036,149.297c0,33.969,11.132,65.96,32.193,92.515\n\t\t\tc27.27,34.383,106.572,116.021,109.934,119.479l7.169,7.375l7.17-7.374c3.364-3.46,82.69-85.116,109.964-119.51\n\t\t\tc21.042-26.534,32.164-58.514,32.164-92.485C333.63,66.974,266.656,0,184.333,0z M285.795,229.355\n\t\t\tc-21.956,27.687-80.92,89.278-101.462,110.581c-20.54-21.302-79.483-82.875-101.434-110.552\n\t\t\tc-18.228-22.984-27.863-50.677-27.863-80.087C55.036,78.002,113.038,20,184.333,20c71.294,0,129.297,58.002,129.296,129.297\n\t\t\tC313.629,178.709,304.004,206.393,285.795,229.355z\" \/><path d=\"M184.333,59.265c-48.73,0-88.374,39.644-88.374,88.374c0,48.73,39.645,88.374,88.374,88.374s88.374-39.645,88.374-88.374\n\t\t\tS233.063,59.265,184.333,59.265z M184.333,216.013c-37.702,0-68.374-30.673-68.374-68.374c0-37.702,30.673-68.374,68.374-68.374\n\t\t\ts68.373,30.673,68.374,68.374C252.707,185.341,222.035,216.013,184.333,216.013z\" \/><\/g><\/svg>\u6765\u81ea\u5317\u4eac<\/div>","protected":false},"excerpt":{"rendered":"<p>\u672c\u8282\u4e3b\u8981\u5b66\u4e60\u53cc\u6307\u9488\u3001\u4f4d\u8fd0\u7b97\u3001\u79bb\u6563\u5316\u3001\u533a\u95f4\u5408\u5e76\u7b49\u77e5\u8bc6\u3002 \u53cc\u6307\u9488\u7b97\u6cd5 \u5e38\u89c1\u7c7b\u578b\uff1a\u6307\u5411\u4e24\u4e2a\u4e0d\u540c\u5e8f\u5217 \u6216\u8005 \u6307\u5411\u540c\u4e00\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,104],"tags":[],"class_list":["post-1234","post","type-post","status-publish","format-standard","hentry","category-study","category-biji"],"_links":{"self":[{"href":"https:\/\/diary.bid\/index.php?rest_route=\/wp\/v2\/posts\/1234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/diary.bid\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diary.bid\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diary.bid\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diary.bid\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1234"}],"version-history":[{"count":1,"href":"https:\/\/diary.bid\/index.php?rest_route=\/wp\/v2\/posts\/1234\/revisions"}],"predecessor-version":[{"id":1235,"href":"https:\/\/diary.bid\/index.php?rest_route=\/wp\/v2\/posts\/1234\/revisions\/1235"}],"wp:attachment":[{"href":"https:\/\/diary.bid\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diary.bid\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diary.bid\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}