{"id":1236,"date":"2024-08-30T18:34:00","date_gmt":"2024-08-30T10:34:00","guid":{"rendered":"https:\/\/diary.bid\/?p=1236"},"modified":"2025-08-30T18:35:14","modified_gmt":"2025-08-30T10:35:14","slug":"%e7%ac%ac%e4%ba%8c%e7%ab%a0-%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/diary.bid\/?p=1236","title":{"rendered":"\u7b2c\u4e8c\u7ae0 \u6570\u636e\u7ed3\u6784"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6570\u636e\u7ed3\u6784\u662f\u5927\u4e00\u4e0b\u7684\u8bfe\u7a0b\uff0c\u603b\u4f53\u5b66\u7684\u8fd8\u597d\uff0c\u5c31\u5f53\u590d\u4e60\u4e00\u4e0b\uff0c\u4ee5\u53ca\u770b\u770b\u6709\u6ca1\u6709\u4ec0\u4e48\u5176\u4ed6\u5185\u5bb9\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-0\">\u94fe\u8868\u4e0e\u90bb\u63a5\u8868<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-1\">\u6570\u7ec4\u6a21\u62df\u5355\u94fe\u8868<\/h3>\n\n\n\n<p>\u4f7f\u7528\u4e24\u4e2a\u6570\u7ec4<code class=\"prettyprint linenums\" >e[N]<\/code>\u548c<code class=\"prettyprint linenums\" >nxt[N]<\/code>\uff0c\u4f7f\u7528\u4e0b\u6807\u5173\u8054\u8d77\u6765\u3002\u5176\u4ed6\u64cd\u4f5c\u4e0e\u6b63\u5e38\u94fe\u8868\u4e00\u6837\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-2\">\u6570\u7ec4\u6a21\u62df\u53cc\u94fe\u8868<\/h3>\n\n\n\n<p>\u4f7f\u7528\u4e09\u4e2a\u6570\u7ec4<code class=\"prettyprint linenums\" >e[N]<\/code>\u3001<code class=\"prettyprint linenums\" >l[N]<\/code>\u548c<code class=\"prettyprint linenums\" >r[N]<\/code>\u3002<\/p>\n\n\n\n<p>\u521d\u59cb\u5316\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >r&#091;0] = 1;\nl&#091;1] = 0;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-3\">\u5355\u8c03\u6808<\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5e8f\u5217\uff0c\u6c42\u4e00\u4e2a\u5e8f\u5217\u5f53\u4e2d\u6bcf\u4e2a\u6570\u5de6\u8fb9\u79bb\u4ed6\u6700\u8fd1\u7684\u4e14\u6bd4\u4ed6\u5c0f\u7684\u6570\u5728\u4ec0\u4e48\u5730\u65b9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >#include &lt;iostream&gt;\nusing namespace std;\nconst int N = 100010;\n\nint n;\nint stk&#091;N], tt;\n\nint main(){\n    cin &gt;&gt; n;\n    for(int i = 0; i &lt; n; i++){\n        int x;\n        cin &gt;&gt; x;\n        while(tt &amp;&amp; stk&#091;tt] &gt;= x) tt --;\n        if(tt) cout &lt;&lt; stk&#091;tt] &lt;&lt; endl;\n        else cout &lt;&lt; -1 &lt;&lt; &#039; &#039;;\n        stk&#091;++tt] = x;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-4\">\u5355\u8c03\u961f\u5217<\/h3>\n\n\n\n<p><strong>\u6ed1\u52a8\u7a97\u53e3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >#include &lt;iostream&gt;\nusing namespcae std;\n\ncoust int N = 1000010;\n\nint n,k;\nint a&#091;N], q&#091;N];\n\nint main(){\n    scanf(&quot;%d&quot;,&amp;n);\n    for(int i = 0; i &lt; n; i++) scanf(&quot;%d&quot;,&amp;a&#091;i]);\n    int hh = 0, tt = -1;\n    for(int i = 0; i &lt; n ; i++){\n        if(hh &lt;= tt &amp;&amp; i - k + 1 &gt; q&#091;hh]) hh++;\n        while (hh &lt;= tt &amp;&amp; a&#091;q&#091;tt]] &gt;= a&#091;i]) tt--;\n        q&#091;++tt] = i;\n        if(i &gt;= k - 1) printf(&quot;%d &quot;,a&#091;q&#091;hh]]);\n    }\n    puts(&quot;&quot;);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-5\">KMP\u7b97\u6cd5<\/h2>\n\n\n\n<p>\u5b9a\u4e49KMP\u6570\u7ec4<code class=\"prettyprint linenums\" >next[i] = j<\/code>\uff0c\u5373\u4ee5<code class=\"prettyprint linenums\" >i<\/code>\u4e3a\u7ec8\u70b9\u7684\u4e00\u6bb5\u7684\u6570\u7ec4\u91cc\uff0c\u524d\u9762<code class=\"prettyprint linenums\" >j<\/code>\u4e2a\u5143\u7d20\u548c\u6700\u540e\u9762<code class=\"prettyprint linenums\" >j<\/code>\u4e2a\u5143\u7d20\u662f\u4e00\u6837\u7684\u3002<\/p>\n\n\n\n<p>\u5339\u914d\u7684\u65f6\u5019\uff0c\u5f53\u5339\u914d\u5230key\u6570\u7ec4\u7684\u7b2c<code class=\"prettyprint linenums\" >k<\/code>\u4f4d\u65f6\uff0c\u4f7f\u7528<code class=\"prettyprint linenums\" >next[k]<\/code>\u5224\u65ad\u8fd9\u4e00\u6bb5\u6570\u7ec4\u6709\u591a\u5c11\u662f\u76f8\u540c\u7684\uff0c\u628akey\u6570\u7ec4\u5411\u540e\u79fb\u52a8<code class=\"prettyprint linenums\" >strlen(key) - next[k]<\/code>\u4f4d\uff0c\u5f97\u5230\u65b0\u7684\u9a8c\u8bc1\u6570\u7ec4\u4f4d\u7f6e\uff0c\u5c31\u662f\u628a\u9a8c\u8bc1\u6570\u7ec4\u6307\u9488\u6307\u5411<code class=\"prettyprint linenums\" >next[k]<\/code>\uff0c\u800c\u6307\u5411\u5339\u914d\u6570\u7ec4\u7684\u6307\u9488\u53ea\u7528\u6bcf\u4e2a\u5faa\u73af\u52a01\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >#include &lt;iostream&gt;\nusing namespace std;\n\nconst int N = 100010, M = 100010;\n\nint n,m;\nint p&#091;N], s&#091;M];\nint nxt&#091;N];\n\nint main(){\n    cin &gt;&gt; n &gt;&gt; p+1 &gt;&gt; m &gt;&gt; s+1;\n\n    \/\/\u6c42next\u7684\u8fc7\u7a0b\n    for(int i = 2, j = 0; i &lt;= n;i++){\n        while(j &amp;&amp; p&#091;i]!=p&#091;j+1]) j = ne&#091;j];\n        if(p&#091;i] == p&#091;j+1]) j++;\n        ne&#091;i] = j;\n    }\n\n    \/\/KMP\u5339\u914d\u7b97\u6cd5\n    for(int i = 1, j = 0; i&lt;=m; i++){\n        while (j &amp;&amp; s&#091;i]!=p&#091;j+1]) j = nxt&#091;j]; \/\/\u5339\u914d\u4e0d\u4e0a\u4f7f\u7528next&#091;j]\u8ba1\u7b97\u524d\u540e\u7f00\u91cd\u590d\u533a\u95f4\u5927\u5c0f\uff0c\u4e00\u76f4\u4f4d\u79fb\u5230\u53ef\u4ee5\u5339\u914d\u4e0a\u3002\n        if(s&#091;i] == p&#091;j+1]) j++;\n        if(j==n){\n            \/\/\u5339\u914d\u6210\u529f\uff01\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250805232237913.png\" alt=\"image-20250805232237913\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-6\">Trie\u6811<\/h2>\n\n\n\n<p>\u7528\u6765\u5feb\u901f\u5b58\u50a8\u548c\u67e5\u627e\u5b57\u7b26\u4e32\u96c6\u5408\u7684\u6570\u636e\u7ed3\u6784\uff0c<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250806150211796.png\" alt=\"image-20250806150211796\"\/><\/figure>\n\n\n\n<p>\u6bcf\u4e2a\u8282\u70b9\u4e00\u4e2a\u5b57\u7b26\uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u6807\u8bb0\u662f\u5426\u4e3a\u7ed3\u5c3e\u3002\u8fd9\u91cc\u4f7f\u7528\u6570\u7ec4\u5b58\u50a8Trie\u6811\uff0c\u6bcf\u4e00\u4e2a\u4f4d\u7f6e\u662f\u4e00\u4e2a\u8282\u70b9\uff0c\u4f7f\u7528<code class=\"prettyprint linenums\" >son<\/code>\u6570\u7ec4\u8bb0\u5f55\u6bcf\u4e2a\u8282\u70b9\u7684\u5b50\u8282\u70b9\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b\u9898\u76ee\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250806150337975.png\" alt=\"image-20250806150337975\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >#include &lt;iostream&gt;\nusing namespace std;\nconst int N = 100010;\n\nint n;\nint son&#091;N]&#091;26], cnt&#091;N] , idx; \/\/idx\u4ee3\u8868\u76ee\u524d\u6570\u7ec4\u5f00\u5230\u54ea\u91cc\uff0c\u4e0b\u6807\u4e3a0\u7684\u4e3a\u7a7a\u8282\u70b9\u3002son\u6570\u7ec4\u8bb0\u5f55\u7684\u662f\u4e0b\u6807\u4e3an\u7684\u8282\u70b9\u7684\u5b50\u8282\u70b9\uff0ccnt\u8bb0\u5f55\u67d0\u4e2a\u5b57\u7b26\u4e32\u7ed3\u5c3e\u7684\u6b21\u6570\uff0c\u521d\u59cb\u662f0\u3002\nchar str&#091;N];\n\nvoid insert(char str&#091;]){\n    int p = 0;\n    for(int i = 0; str&#091;i]; i++){\n        int u = str&#091;i] - &#039;a&#039;;\n        if(!son&#091;p]&#091;u]) son&#091;p]&#091;u] = ++idx;\n        p = son&#091;p]&#091;u];\n    }\n    cnt&#091;p] ++;\n}\n\nint query(char str&#091;]){\n    int p = 0;\n    for(int i = 0; str&#091;i]; i++){\n        int u = str&#091;i] - &#039;a&#039;;\n        if(!son&#091;p]&#091;u]) return 0;\n        p = son&#091;p]&#091;u];\n    }\n    return cnt&#091;p];\n}\n\nint main(){\n    int n;\n    scanf(&quot;%d&quot;,&amp;n);\n    while(n--){\n        char op&#091;2];\/\/\u8bfb\u6210\u5b57\u7b26\u4e32\u907f\u514dscanf\u8bfb\u5b57\u7b26\u51fa\u73b0\u7a7a\u683c\u56de\u8f66\n        scanf(&quot;%s%s&quot;,op,str);\n        if(op&#091;0]==&#039;I&#039;) insert(str);\n        else query(str);\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-7\">\u5e76\u67e5\u96c6<\/h2>\n\n\n\n<p>\u5e76\u67e5\u96c6\u652f\u6301\u4ee5\u4e0b\u64cd\u4f5c\u4e14\u53ef\u4ee5\u8fd1\u4e4e$O(1)$\u5feb\u901f\u5b8c\u6210\u4ee5\u4e0b\u64cd\u4f5c\uff1a1\ufe0f\u20e3\u5c06\u4e24\u4e2a\u96c6\u5408\u5408\u5e76\uff1b2\ufe0f\u20e3\u8be2\u95ee\u4e24\u4e2a\u5143\u7d20\u662f\u5426\u5728\u4e00\u4e2a\u96c6\u5408\u5f53\u4e2d\u3002<\/p>\n\n\n\n<p><strong>\u57fa\u672c\u539f\u7406\uff1a<\/strong>\u4f7f\u7528\u6811\u7ef4\u62a4\u96c6\u5408\uff0c\u6bcf\u68f5\u6811\u662f\u4e00\u4e2a\u96c6\u5408\uff0c\u6bcf\u4e00\u4e2a\u96c6\u5408\u6709\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\uff0c\u6811\u6839\u7684\u7f16\u53f7\u5c31\u662f\u6574\u4e2a\u96c6\u5408\u7684\u7f16\u53f7\uff0c\u6bcf\u4e00\u4e2a\u8282\u70b9\u5b58\u50a8\u4e00\u4e2a\u5b83\u7684\u7236\u8282\u70b9\uff0c<code class=\"prettyprint linenums\" >p[x]<\/code>\u8868\u793ax\u7684\u7236\u8282\u70b9\u3002\u6839\u8282\u70b9<code class=\"prettyprint linenums\" >p[x]=x<\/code>\u5373\u96c6\u5408\u7f16\u53f7\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250806161841568.png\" alt=\"image-20250806161841568\"\/><\/figure>\n\n\n\n<p>\u95ee\u9898\u4e00\uff1a\u5982\u4f55\u5224\u65ad\u6811\u6839\uff0c\u7236\u8282\u70b9\u6307\u5411\u81ea\u5df1\uff1a<code class=\"prettyprint linenums\" >if(p[x]==x)<\/code><\/p>\n\n\n\n<p>\u95ee\u9898\u4e8c\uff1a\u5982\u4f55\u6c42x\u7684\u96c6\u5408\u7f16\u53f7\uff0c\u901a\u8fc7\u8bb0\u5f55\u7684\u7236\u8282\u70b9\u4e00\u76f4\u5f80\u4e0a\u627e\uff1a<code class=\"prettyprint linenums\" >while(p[x] != x) x = p[x];<\/code><\/p>\n\n\n\n<p>\u95ee\u9898\u4e09\uff1a\u5982\u4f55\u5408\u5e76\u4e24\u4e2a\u96c6\u5408\uff1a\u5047\u8bbe<code class=\"prettyprint linenums\" >p[x]<\/code>\u7684x\u7684\u96c6\u5408\u7f16\u53f7\uff0c<code class=\"prettyprint linenums\" >p[y]<\/code>\u662fy\u7684\u96c6\u5408\u7f16\u53f7\uff0c\u76f4\u63a5<code class=\"prettyprint linenums\" >p[x] = y<\/code>\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u95ee\u9898\u56db\uff1a\u95ee\u9898\u4e8c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u6bd4\u8f83\u9ad8\uff0c\u53ef\u4ee5\u8fdb\u884c<strong>\u8def\u5f84\u4f18\u5316<\/strong>\uff1a\u67e5\u627ex\u7684\u6839\u8282\u70b9\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u628ax\u548c\u6240\u6709\u8def\u5f84\u4e0a\u7684\u8282\u70b9\u90fd\u76f4\u63a5\u6307\u5411\u6839\u8282\u70b9\uff0c\u4f18\u5316\u4e0b\u4e00\u6b21\u67e5\u627e\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b\u9898\u76ee\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250806152950644.png\" alt=\"image-20250806152950644\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >#include &lt;iostream&gt;\nusing namespace std;\nconst int N = 100010;\n\nint n;\nint p&#091;N];\/\/\u8bb0\u5f55\u6bcf\u4e2a\u5143\u7d20\u7684\u7236\u8282\u70b9\u662f\u8c01\n\nint find(int x){ \/\/\u5e26\u8def\u5f84\u538b\u7f29\u4f18\u5316\uff0c\u4f7f\u7528\u9012\u5f52\u8c03\u7528\n    if(p&#091;x]!=x) p&#091;x] = find(p&#091;x]);\n    return p&#091;x];\n}\n\nint main(){\n    scanf(&quot;%d%d&quot;,&amp;n,&amp;m);\n    for(int i = 1; i &lt;=n ; i++) p&#091;i] = i; \/\/\u6700\u5f00\u59cb\u6bcf\u4e2a\u5143\u7d20\u5728\u4e00\u4e2a\u96c6\u5408\n    while(m--){\n        char op&#091;2];\n        int a,b;\n        scanf(&quot;%s%d%d&quot;,op,&amp;a,&amp;b);\n        if(op&#091;0]==&#039;M&#039;) p&#091;find(a)] = find(b);\n        else{\n            if(find(a) == find(b)) puts(&quot;Yes&quot;);\n            else puts(&quot;No&quot;);\n        }\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-8\">\u5806<\/h2>\n\n\n\n<p><strong>\u5982\u4f55\u624b\u5199\u4e00\u4e2a\u5806\uff1f<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u63d2\u5165\u4e00\u4e2a\u6570 <code class=\"prettyprint linenums\" >heap[++size]; up(size);<\/code><\/li>\n\n\n\n<li>\u6c42\u8fd9\u4e2a\u96c6\u5408\u4e4b\u4e2d\u7684\u6700\u5c0f\u503c <code class=\"prettyprint linenums\" >heap[1]<\/code><\/li>\n\n\n\n<li>\u5220\u9664\u6700\u5c0f\u503c <code class=\"prettyprint linenums\" >heap[1] = heap[size]; size--; down(1);<\/code><\/li>\n\n\n\n<li>\u5220\u9664\u4efb\u4f55\u4e00\u4e2a\u5143\u7d20 <code class=\"prettyprint linenums\" >heap[k] = heap[size]; size--; down(k); up(k);<\/code><\/li>\n\n\n\n<li>\u4fee\u6539\u4efb\u4f55\u4e00\u4e2a\u5143\u7d20 <code class=\"prettyprint linenums\" >heap[k] = x; down(x); up(x);<\/code><\/li>\n<\/ol>\n\n\n\n<p><strong>\u5b9a\u4e49\uff1a<\/strong>\u5806\u662f\u4e00\u4e2a\u5b8c\u5168\u4e8c\u53c9\u6811\u3002\u5c0f\u6839\u5806\u9012\u5f52\u5b9a\u4e49\uff1a\u6bcf\u4e2a\u8282\u70b9\u5c0f\u4e8e\u7b49\u4e8e\u5de6\u53f3\u513f\u5b50\uff0c\u5373\u6839\u8282\u70b9\u5c31\u662f\u6700\u5c0f\u503c\u3002<\/p>\n\n\n\n<p><strong>\u5b58\u50a8\uff1a<\/strong>\u5047\u8bbe\u6839\u8282\u70b9\u662f$1$\uff0c\u5219x\u7684\u5de6\u513f\u5b50\u662f$2x$\uff0cx\u7684\u53f3\u513f\u5b50\u662f$2x+1$\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-9\">\u5806\u6392\u5e8f<\/h3>\n\n\n\n<p>\u5176\u5b9e\u5229\u7528\u7684\u662f\u6c42\u96c6\u5408\u6700\u5c0f\u503c\u548c\u5220\u9664\u6700\u5c0f\u503c\u4e24\u4e2a\u64cd\u4f5c\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u5b8c\u6210down\u64cd\u4f5c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nconst int N = 100010;\n\nint n, m;\nint h&#091;N], size;\n\nvoid down(int u){\n     int t = u;\n    if(u*2&lt;=size &amp;&amp; h&#091;u*2]&lt;h&#091;t]) t = u*2;\n    if(u*2+1&lt;=size &amp;&amp; h&#091;u*2+1]&lt;h&#091;t]) t = u*2+1;\n    if(u!=t){\n        swap(h&#091;u],h&#091;t]);\n        down(t);\n    }\n}\n\nvoid up(int u){\n    while(u\/2 &amp;&amp; h&#091;u\/2] &gt; h&#091;u]){\n        swap(h&#091;u\/2],h&#091;u]);\n        u\n    }\n}\n\nint main(){\n    scanf(&quot;%d%d&quot;,&amp;n,&amp;m);\n    for(int i = 1; i &lt;= n; i++) scanf(&quot;%d&quot;, &amp;h&#091;i]);\n    size = n;\n\n    for(int i = n\/2; i; i--) down(i); \/\/\u5efa\u5806\uff0c\u4e0d\u9700\u8981down\u6700\u540e\u4e00\u5c42\n\n    while(m--){\n        printf(&quot;%d&quot;,&amp;h&#091;1]);\n        h&#091;1] = h&#091;size];\n        size--;\n        down(1);\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-10\">\u54c8\u5e0c\u8868<\/h2>\n\n\n\n<p>\u5b58\u50a8\u7ed3\u6784\uff1a<strong>\u5f00\u653e\u5bfb\u5740\u6cd5<\/strong>\u3001<strong>\u62c9\u94fe\u6cd5<\/strong><\/p>\n\n\n\n<p><strong>\u5b57\u7b26\u4e32\u54c8\u5e0c\u65b9\u5f0f<\/strong>\uff1a\u628a\u6bcf\u4e00\u79cd\u5b57\u7b26\u6620\u5c04\u6210\u6570\u5b57\uff0c\u4f7f\u7528\u4ee5\u4e0b\u516c\u5f0f\u8ba1\u7b97\uff1a<br>$$<br>ABC\u2026A = \\<br>(1\\times p^{n-1} + 2\\times p^{n-2} + 3\\times p^{n-3} +\u20261\\times p^0)\\ mod\\ Q<br>$$<br>\u5176\u4e2d\u53ef\u4ee5 $p=131\u621613331$ \uff0c $Q = 2^{64}$ \uff0c\u53ef\u4ee5\u964d\u4f4e\u91cd\u590d\u6982\u7387\u3002 $Q = 2^{64}$ \u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code class=\"prettyprint linenums\" >unsigned long long<\/code>\u76f4\u63a5\u5b58\u50a8\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u628a\u5b57\u7b26\u524d\u7f00\u54c8\u5e0c\u548c\u8bb0\u4e3a<code class=\"prettyprint linenums\" >h[i]<\/code>\uff0c\u6bd4\u5982$(L+1)\\ -\\ R$\u8fd9\u4e00\u6bb5\u7684\u54c8\u5e0c\u503c\u4e3a $h[R]-h[L]\\times p^{R-L+1}$ \uff0c\u4ee5\u53ca\u9012\u63a8 $h[i] = h[i-1]\\times p + str(i)$ \u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250807191341748.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>\u4f8b\u9898\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/2bpic.oss-cn-beijing.aliyuncs.com\/image-20250807195605384.png\" alt=\"image-20250807195605384\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >#include &lt;iostream&gt;\nusing namespace std;\n\ntypedef unsigned long long ULL;\nconst int N = 100010, P = 131;\n\nint n,m;\nchar str&#091;N];\nULL h&#091;N],p&#091;N];\n\nULL get(int l, int r){\n    return h&#091;r] - h&#091;l-1]*p&#091;r-l+1];\n}\n\nint main(){\n    scanf(&quot;%d%d%s&quot;, &amp;n, &amp;m, str+1);\n    p&#091;0] = 1;\n    for(int i = 1; i &lt;= n; i++){\n        p&#091;i] = p&#091;i - 1]*P;\n        h&#091;i] = h&#091;i - 1]*P + str&#091;i];\n    }\n    while(m--){\n        int l1,r1,l2,r2;\n        scanf(&quot;%d%d%d%d&quot;, &amp;l1,&amp;r1,&amp;l2,&amp;r2);\n        if(get(l1,r1) == get(l2,r2)) puts(&quot;Yes&quot;);\n        else puts(&quot;No&quot;);\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-11\">STL\u5e38\u7528\u5bb9\u5668<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-12\">vector<\/h3>\n\n\n\n<p>\u6570\u7ec4\u957f\u5ea6\u53ef\u4ee5\u52a8\u6001\u53d8\u5316\uff0c\u500d\u589e\u7684\u601d\u60f3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >#include &lt;vector&gt;\nusing namespace std;\n\nint main(){\n    vector&lt;int&gt; a(10,3);\/\/\u5b9a\u4e49\u4e00\u4e2a\u957f\u5ea6\u4e3a10\u7684int\u7c7b\u578bvector\uff0c\u6bcf\u4e00\u4f4d\u90fd\u662f3\n    a.size(); \/\/\u8fd4\u56de\u5143\u7d20\u4e2a\u6570\uff0c\u6240\u6709\u5bb9\u5668\u90fd\u6709\n    a.empty(); \/\/\u8fd4\u56de\u662f\u5426\u4e3a\u7a7a\uff0c\u6240\u6709\u5bb9\u5668\u90fd\u6709\n    a.clear(); \/\/\u6e05\u7a7a\n    a.front();a.back();\/\/\u8fd4\u56de\u7b2c\u4e00\u4e2a\u6570\/\u6700\u540e\u4e00\u4e2a\u6570\n    a.push_back();a.pop_back();\/\/\u5411\u6700\u540e\u63d2\u5165\/\u5220\u9664\u4e00\u4e2a\u6570\n    a.begin();a.end();\/\/\u7b2c\u4e00\u4e2a\u6570\/\u6700\u540e\u4e00\u4e2a\u6570\u7684\u540e\u9762\u4e00\u4e2a\u6570\n    a&#091;];\/\/ \u7c7b\u4f3c\u4e8e\u6570\u7ec4\u8c03\u7528\n    vector&lt;int&gt; a(4,3), b(3,4);\n    if(a &lt; b) puts(&quot;a &lt; b&quot;); \/\/\u652f\u6301\u6bd4\u8f83\u8fd0\u7b97\uff0c\u4f7f\u7528\u201c\u5b57\u5178\u5e8f\u201d\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-13\">pair<\/h3>\n\n\n\n<p><code class=\"prettyprint linenums\" >pair&lt;int, int&gt;<\/code>\uff0c\u4f7f\u7528<code class=\"prettyprint linenums\" >p.first<\/code>\u6216<code class=\"prettyprint linenums\" >p.second<\/code>\u83b7\u53d6\u7b2c\u4e00\u3001\u7b2c\u4e8c\u4e2a\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u652f\u6301\u6bd4\u8f83\u8fd0\u7b97\uff0c\u4ee5first\u4e3a\u7b2c\u4e00\u5173\u952e\u5b57\uff0c\u4ee5second\u4e3a\u7b2c\u4e8c\u5173\u952e\u5b57\u3002<\/p>\n\n\n\n<p>\u591a\u5c42\u5d4c\u5957\uff1a<code class=\"prettyprint linenums\" >pair&lt;int, pair&lt;int, int&gt;&gt;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-14\">string<\/h3>\n\n\n\n<p>\u5b57\u7b26\u4e32\uff0c<code class=\"prettyprint linenums\" >substr()<\/code>\u8fd4\u56de\u5b50\u4e32\uff0c<code class=\"prettyprint linenums\" >c_str()<\/code>\u8fd4\u56de\u5b57\u7b26\u6570\u7ec4\u8d77\u59cb\u5730\u5740<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >string a = &quot;lxzs&quot;;\na += &quot;nb&quot;; \/\/\u53ef\u4ee5\u76f4\u63a5\u589e\u52a0\na.size();\na.empty();\na.clear;\na.substr(1,2);\/\/\u8fd4\u56de\u5b50\u4e32\uff0c\u7b2c\u4e00\u4e2a\u5173\u952e\u5b57\u662f\u8d77\u59cb\u4f4d\u7f6e\uff0c\u7b2c\u4e8c\u4e2a\u662f\u5b50\u4e32\u957f\u5ea6\nprintf(&quot;%s\\n&quot;, a.c_str());<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-15\">queue<\/h3>\n\n\n\n<p>\u961f\u5217\uff0c<code class=\"prettyprint linenums\" >push()<\/code>\uff0c<code class=\"prettyprint linenums\" >front()<\/code>\uff0c<code class=\"prettyprint linenums\" >pop()<\/code>\uff0c\u6709empty\u3001size\u51fd\u6570\uff0c\u6ca1\u6709clear\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >a.push();\/\/\u961f\u5c3e\u63d2\u5165\na.front();\/\/\u8fd4\u56de\u961f\u5934\u5143\u7d20\na.back();\/\/\u8fd4\u56de\u961f\u5c3e\u5143\u7d20\na.pop();\/\/\u5f39\u51fa\u961f\u5934\u5143\u7d20<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-16\">priority_queue<\/h3>\n\n\n\n<p>\u4f18\u5148\u961f\u5217\uff0c<code class=\"prettyprint linenums\" >push()<\/code>\uff0c<code class=\"prettyprint linenums\" >top()<\/code>\uff0c<code class=\"prettyprint linenums\" >pop()<\/code>\uff0c\u9ed8\u8ba4\u5927\u6839\u5806<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >a.push();\/\/\u5806\u4e2d\u63d2\u5165\na.top();\/\/\u8fd4\u56de\u5806\u9876\u5143\u7d20\na.pop();\/\/\u5f39\u51fa\u5806\u9876\u5143\u7d20<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u60f3\u4f7f\u7528\u5c0f\u6839\u5806\uff0c\u7b2c\u4e00\u79cd\u53ef\u4ee5\u76f4\u63a5\u6240\u6709\u5143\u7d20\u6dfb\u52a0\u8d1f\u53f7\u3002\u6216\u8005\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >priority_queue&lt;int, vector&lt;int&gt;, greater&lt;int&gt;&gt; q;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-17\">stack<\/h3>\n\n\n\n<p>\u6808\uff0c<code class=\"prettyprint linenums\" >push()<\/code>\uff0c<code class=\"prettyprint linenums\" >top()<\/code>\uff0c<code class=\"prettyprint linenums\" >pop()<\/code>\u3002\u8ddfqueue\u5dee\u4e0d\u591a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-18\">deque<\/h3>\n\n\n\n<p>\u53cc\u7aef\u961f\u5217\u3002\u6709empty\u3001size\u3001clear\u51fd\u6570\u3002\u6548\u7387\u8f83\u4f4e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >a.front();\/\/\u8fd4\u56de\u961f\u5934\u5143\u7d20\na.back();\/\/\u8fd4\u56de\u961f\u5c3e\u5143\u7d20\na.push_back();a.pop_back(); \/\/\u961f\u5c3e\u63d2\u5165\u3001\u5f39\u51fa\u4e00\u4e2a\u5143\u7d20\na.push_front();a.pop_back(); \/\/\u961f\u5934\u63d2\u5165\u3001\u5f39\u51fa\na&#091;];\na.begin();a.end();<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-19\">set, map, multiset, multimap<\/h3>\n\n\n\n<p>\u57fa\u4e8e\u5e73\u8861\u4e8c\u53c9\u6811\uff08\u7ea2\u9ed1\u6811\uff09\uff0c\u52a8\u6001\u7ef4\u62a4\u6709\u5e8f\u5e8f\u5217\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >size();\nempty();\nclear();\n\nset\/multiset:\n    insert(); \/\/\u63d2\u5165\u4e00\u4e2a\u6570\n    find(); \/\/\u67e5\u627e\u4e00\u4e2a\u6570\n    count(); \/\/\u8fd4\u56de\u67d0\u4e00\u4e2a\u6570\u7684\u4e2a\u6570\n    erase();\n        \/\/(1) \u8f93\u5165\u662f\u4e00\u4e2a\u6570x\uff0c\u5220\u9664\u6240\u6709\u503c\u4e3ax\u7684\u6570\uff0cO(log(n));\n        \/\/(2) \u8f93\u5165\u662f\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u5220\u9664\u8fd9\u4e2a\u8fed\u4ee3\u5668\n    lower_bound;upper_bound;\/\/\u7b2c\u4e00\u4e2a\u662f\u8fd4\u56de\u5927\u4e8e\u7b49\u4e8ex\u7684\u6700\u5c0f\u7684\u6570\uff0c\u7b2c\u4e8c\u4e2a\u8fd4\u56de\u5927\u4e8ex\u7684\u6700\u5c0f\u7684\u6570\u3002\uff08\u90fd\u662f\u8fd4\u56de\u8fed\u4ee3\u5668\uff09\n\nmap\/multimap:\n    insert();\/\/\u63d2\u5165\u7684\u6570\u662f\u4e00\u4e2apair\n    erase;\/\/\u8f93\u5165\u7684\u53c2\u6570\u662fpair\u6216\u8005\u8fed\u4ee3\u5668\n    find();\n    a&#091;];\n\n\/\/eg.\nmap&lt;string,int&gt; a;\na&#091;&quot;lx&quot;] = 1;\ncout &lt;&lt; a&#091;&quot;lx&quot;] &lt;&lt; endl; \/\/\u65f6\u95f4\u590d\u6742\u5ea6O(log(n))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-20\">unordered_set, unordered_map, unordered_multiset, unordered_multimap<\/h3>\n\n\n\n<p>\u54c8\u5e0c\u8868<\/p>\n\n\n\n<p>\u548c\u4e0a\u9762\u7c7b\u4f3c\uff0c\u589e\u5220\u6539\u67e5\u7684\u65f6\u95f4\u590d\u6742\u5ea6O(1) \u3002<\/p>\n\n\n\n<p>\u4e0d\u652f\u6301<code class=\"prettyprint linenums\" >lower_bound()<\/code>\u548c<code class=\"prettyprint linenums\" >upper_bound()<\/code>\u3001\u8fed\u4ee3\u5668\u7684++\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-21\">bitset<\/h3>\n\n\n\n<p>\u538b\u4f4d\u3002\u6bd4\u5982\u8981\u5f001024\u5927\u5c0f\u7684bool\u6570\u7ec4\uff0c\u9700\u89811024\u5b57\u8282\u7a7a\u95f4\u3002\u4f46\u662f\u53ef\u4ee5\u7528bitset\u5b58\u6210128\u5b57\u8282\uff0c\u77018\u500d\u7a7a\u95f4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint linenums\" >bitset&lt;10000&gt; S;\n\/\/\u652f\u6301\u6240\u6709\u7684\u4f4d\u8fd0\u7b97\u64cd\u4f5c\n~, &amp;, |, ^\n&gt;&gt;, &lt;&lt;\n==, !=\nS&#091;]\n\ncount(); \/\/\u8fd4\u56de\u6709\u591a\u5c11\u4e2a1\nany(); \/\/\u5224\u65ad\u662f\u5426\u81f3\u5c11\u6709\u4e00\u4e2a\u4e3a1\nnone(); \/\/\u5224\u65ad\u662f\u5426\u5168\u4e3a0\nset(); \/\/\u628a\u6240\u6709\u4f4d\u7f6e\u62101\nset(k, v); \/\/\u628a\u7b2ck\u4f4d\u53d8\u6210v\nreset(); \/\/\u628a\u6240\u6709\u4f4d\u53d8\u62100\nflip(); \/\/\u7b49\u4ef7\u4e8e~\nflip(k); \/\/\u628a\u7b2ck\u4f4d\u53d6\u53cd<\/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>\u6570\u636e\u7ed3\u6784\u662f\u5927\u4e00\u4e0b\u7684\u8bfe\u7a0b\uff0c\u603b\u4f53\u5b66\u7684\u8fd8\u597d\uff0c\u5c31\u5f53\u590d\u4e60\u4e00\u4e0b\uff0c\u4ee5\u53ca\u770b\u770b\u6709\u6ca1\u6709\u4ec0\u4e48\u5176\u4ed6\u5185\u5bb9\u3002 \u94fe\u8868\u4e0e\u90bb\u63a5\u8868 \u6570\u7ec4\u6a21\u62df\u5355\u94fe\u8868 [&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-1236","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\/1236","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=1236"}],"version-history":[{"count":1,"href":"https:\/\/diary.bid\/index.php?rest_route=\/wp\/v2\/posts\/1236\/revisions"}],"predecessor-version":[{"id":1237,"href":"https:\/\/diary.bid\/index.php?rest_route=\/wp\/v2\/posts\/1236\/revisions\/1237"}],"wp:attachment":[{"href":"https:\/\/diary.bid\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diary.bid\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diary.bid\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}