{"id":100,"date":"2023-03-28T17:39:49","date_gmt":"2023-03-28T09:39:49","guid":{"rendered":"https:\/\/solost.cn\/?p=100"},"modified":"2023-03-28T17:39:49","modified_gmt":"2023-03-28T09:39:49","slug":"193","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=100","title":{"rendered":"AcWing &#8211; 3485. \u6700\u5927\u5f02\u6216\u548c"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/image1-5.png\" alt=\"image(1).png\" title=\"image(1).png\"><\/p>\n<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/www.acwing.com\/problem\/content\/description\/3488\/\">\u9898\u76ee\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u89e3<\/h2>\n<pre><code class=\"lang-cpp\">#include&lt;map&gt;\n#include&lt;set&gt;\n#include&lt;stack&gt;\n#include&lt;queue&gt;\n#include&lt;cmath&gt;\n#include&lt;vector&gt;\n#include&lt;bitset&gt;\n#include&lt;cstdio&gt;\n#include&lt;cstring&gt;\n#include&lt;fstream&gt;\n#include&lt;cstdlib&gt;\n#include&lt;iostream&gt;\n#include&lt;algorithm&gt;\n#include&lt;unordered_map&gt;\n\nusing namespace std;\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\ntypedef long long ll;\ntypedef pair&lt;int,int&gt; PII;\ntypedef unsigned long long ull;\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 3100010;\nint s[N];\nint tr[N][2], idx, cnt[N];\nvoid insert(int x, int v){\n    int p = 0;\n    for(int i = 30; i &gt;= 0; i--){\n        int u = x &gt;&gt; i &amp; 1;\n        if(!tr[p][u]) tr[p][u] = ++idx;\/\/\u5982\u679c\u5f53\u524d\u6811\u6ca1\u6709\u5b50\u6811\uff0c\u90a3\u4e48\u73b0\u5728\u5b50\u6811\u6570\u76ee\u52a01\n        p = tr[p][u];\/\/\u5982\u679c\u5b58\u5728\u5b50\u6811\uff0c\u90a3\u4e48\u5c31\u628ap\u79fb\u52a8\u5230\u5f53\u524d\u5b50\u6811\u4f4d\u7f6e\n        cnt[p] += v;\n    \/*\u8bb0\u5f55\u5f53\u524d\u70b9\u7684\u5b50\u6811\u4e2a\u6570\uff0c\u56e0\u4e3a\u6bcf\u4e2a\u6570\u90fd\u80fd\u5bf9\u6bcf\u4e00\u4f4d\u4ea7\u751f\u5f71\u54cd\uff0c\u800c\u4e0d\u662f\u4e4b\u524dtrie\u6811\u7684\u6a21\u677f\u63d0\u90a3\u6837\u53ea\u628a\u6574\u4e2a\u5b57\u7b26\u904d\u5386\u5b8c\u624d\u7b97\u4e00\u4e2a*\/\n    }\n}\n\nint query(int x){\n    int res = 0, p = 0;\n    for(int i = 30; i &gt;= 0; i--){\n        int u = x &gt;&gt; i &amp; 1;\n        if(tr[p][!u]) res = res * 2 + 1, p = tr[p][!u];\n        else res *= 2, p = tr[p][u];\n    }\n    return res;\n}\n\nvoid solve(){\n    int n, m;\n    cin &gt;&gt; n &gt;&gt; m;\n    for(int i = 1; i &lt;= n; i++){\n        int x;\n        cin &gt;&gt; x;\n        s[i] = s[i - 1] ^ x;\n    }\n    int ans = 0;\n    insert(s[0], 1);\n    for(int i = 1; i &lt;= n; i++){\n        if(i - m - 1 &gt;= 0) insert(s[i - m - 1], - 1);\n    \/*\n    \u56e0\u4e3a\u5f02\u6216\u548c\u8ba1\u7b97\u65f6\u65f6s[r] ^ s[l - 1], l = i - m + 1, l - 1 = i - m,\u6240\u4ee5l-1\u9879\u6ca1\u7528\n    *\/\n        ans = max(ans, query(s[i]));\n        insert(s[i], 1);\n    }\n    cout &lt;&lt; ans &lt;&lt; endl;\n}\nint main(){\n    \/\/ IOS;\n    int t = 1;\n    \/\/ cin &gt;&gt; t;\n    while(t--){\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u9898\u76ee\u94fe\u63a5 \u9898\u89e3 #include&lt;map&gt; #include&lt;set&gt; #include&lt;stack&gt; #include&lt;queue&gt; #include&lt;cmath&gt; #include&lt;vector&gt; #include&lt;bitset&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;fstream&gt; #include&lt;cstdlib&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;unordered_map&gt; using namespace std; #define x first #define y second #define endl &#039;\\n&#039; #define IOS \\ ios_base::sync_with_stdio(0); \\ cin.tie(0); \\ cout.tie(0); typedef long long ll; typedef pair&lt;int,int&gt; PII; typedef unsigned long long ull; const int INF = 0x3f3f3f3f, mod [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[42,43],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-solution","tag-trie","tag-43"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}