{"id":19,"date":"2023-01-19T14:40:00","date_gmt":"2023-01-19T06:40:00","guid":{"rendered":"https:\/\/solost.cn\/?p=19"},"modified":"2023-02-02T00:55:04","modified_gmt":"2023-02-01T16:55:04","slug":"39","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=19","title":{"rendered":"2023\u725b\u5ba2\u5bd2\u5047\u7b97\u6cd5\u57fa\u7840\u96c6\u8bad\u84252 L-Tokitsukaze and Three Integers"},"content":{"rendered":"<h1>2023\u725b\u5ba2\u5bd2\u5047\u7b97\u6cd5\u57fa\u7840\u96c6\u8bad\u84252 L-Tokitsukaze and Three Integers<\/h1>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/1665745202.png\" alt=\"\" title=\"\"><\/p>\n<h1>solution<\/h1>\n<p>\u6211\u4eec\u5148\u6765\u5206\u6790\u4e00\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u5bfb\u627e\u4e09\u4e2a\u6570\uff0c\u7136\u540e\u6ee1\u8db3\u4e00\u5b9a\u7684\u6761\u4ef6\uff0c\u7531\u4e8en=5000,n\u7684\u4e09\u6b21\u65b9\u7684\u590d\u6742\u5ea6\u80af\u5b9a\u662f\u4e0d\u53ef\u53d6\u7684\uff0c\u6211\u4eec\u5c31\u5f97\u60f3\u529e\u6cd5\u4f18\u5316\u5e38\u6570\u3002<\/p>\n<p>1.\u7b2c\u4e00\u6b21\u7684\u9519\u8bef\u5c1d\u8bd5\uff0c\u4f7f\u7528vector&lt;pair&lt;int, pair&lt;int, int&gt;&gt;&gt;\uff0c\u7b2c\u4e00\u7ef4\u5ea6\u5b58\u653ea[i] <em> a[j] % mod\uff0c\u7b2c\u4e8c\u7ef4\u5ea6\u5b58\u653ei,j,\u7136\u540e\u518d\u679a\u4e3ea[i]\uff0c\u7528f[(a[i] <\/em> a[j] % mod + a[i] % mod) % mod]++,\u6765\u5b58\u653e5000\u4ee5\u5185\u7684i\u7b49\u4e8e\u65f6\u7684\u7b54\u6848\uff0c\u6700\u540e\u518d\u5c06f[i]\u51cf\u53bb\uff08a[i] <em> a[j] + a[i]\u548ca[i] <\/em> a[j] + a[j])\u8fd9\u79cd\u60c5\u51b5\u3002\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u57fa\u672c\u548c\u66b4\u529b\u6ca1\u5565\u533a\u522b\uff0c\u5c5e\u4e8e\u8131\u88e4\u5b50\u653e\u5c41\u4e86\u3002<\/p>\n<p>2.\u7b2c\u4e8c\u6b21\u5c1d\u8bd5\uff0c\u6211\u4eec\u6362\u4e2a\u601d\u8def\uff0cai<em>aj\u6ca1\u529e\u6cd5\u538b\u7f29\uff08ps.\u521a\u5f00\u59cb\u6ca1\u60f3\u5230\u538b\u7f29\u8fd9\u4e2a\uff09\uff0c\u6211\u4eec\u5c31\u538b\u7f29a[i],\u6211\u4eec\u5c06a[i] % mod\uff0c\u5b58\u653e\u5230b[i]\u91cc\u9762\uff0c\u8ba1\u7b97a[i] % mod\u540e\u76f8\u540c\u7684\u6570\u76ee\uff0c\u6700\u540e\u518d\u5c06(a[i] <\/em> a[j] <em> % mod + i % mod) % mod\u7684\u6570\u76ee\u8ba1\u7b97\u51fa\u6765\u5c31\u53ef\u4ee5\u4e86\uff0c\u518d\u51cf\u53bba[i] <\/em> a[j] + a[i]\u548ca[i] <em> a[j] + a[j])\u8fd9\u79cd\u60c5\u51b5\u3002\u8fd9\u79cd\u60c5\u51b5\u4f18\u5316\u4e86\u4e00\u90e8\u5206\uff0c\u4f46\u662f\u4f18\u5316\u7a0b\u5ea6\u8fd8\u662f\u4e0d\u591f\uff0c\u5982\u679ca[i] % mod\uff0c\u4f46\u662fmod ==5000 == n\u90a3\u5c31\u76f8\u5f53\u4e8e\u6ca1\u6709\u4f18\u5316\u3002\u4e8e\u662f\u6211\u4eec\u5c06\u77db\u5934\u8f6c\u5411\u4f18\u5316a[i] <\/em> a[j]<\/p>\n<p>3.\u4e8e\u662f\u6709\u4e86\u89e3\u6cd5\u4e09\uff0c\u6211\u4eec\u5c06b[a[i] * a[j] % mod]\u7684\u6570\u76ee\u5148\u7b97\u51fa\u6765\uff0c\u7136\u540e\u679a\u4e3ef[a[i] % mod + j % mod]\uff0ci\u5c5e\u4e8e1-n\uff0cj\u5c5e\u4e8e0-p -1\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u7b54\u6848\u4e86\u3002<\/p>\n<p>show code<\/p>\n<pre><code class=\"C++\">#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 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;\nconst int N = 2e5 + 10;\nll a[N], f[5100], b[5100];\/\/\u7531\u4e8eb\u91cc\u9762\u5b58\u50a8\u7684\u662f\u6b21\u6570\uff0c\u56e0\u6b64\u6709\u53ef\u80fd\u4f1a\u7206int\uff0c\u6240\u4ee5\u987a\u4fbf\u5b58\u6210ll\nvoid solve(){\n    int n, p;\n    cin &gt;&gt; n &gt;&gt; p;\n    int mod = p;\n    for(int i = 1; i &lt;= n; i++){\n        cin &gt;&gt; a[i];\n    }\n    for(int i = 1; i &lt;= n; i++){\n        for(int j = i + 1; j &lt;= n; j++){\n            b[(1ll * a[i] * a[j]) % mod]++;\n            ll t1 = ((1ll * a[i] * a[j]) % mod + a[i] % mod) % mod;\n            ll t2 = ((1ll * a[i] * a[j]) % mod + a[j] % mod) % mod;\/\/\u51cf\u53bb\u6709\u4e24\u4e2a\u6570\u76f8\u540c\u7684\u60c5\u51b5\n            f[t1]--;\n            f[t2]--;\n        }\n    }\n    for(int i = 1; i &lt;= n; i++){\n        for(int j = 0; j &lt; p; j++){\n            int t = (a[i] % mod + j % mod) % mod;\n            f[t] += b[j];\n        }\n    }\n    for(int i = 0; i &lt; p; i++){\n        cout &lt;&lt; f[i] * 2 &lt;&lt; &quot; &quot;;\/\/\u56e0\u4e3a\u4e09\u5143\u7ec4\u524d\u4e24\u4e2a\u6570\u4ea4\u6362\u65e0\u6240\u8c13\uff0c\u6240\u4ee5\u00d72\uff0c\u6211\u4eec\u8ba1\u7b97\u7684\u65f6\u5019\u4e0d\u4f1a\u7b97i,j\u548cj,i\u53ea\u4f1a\u7b97\u4e00\u904d\n    }\n    cout &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>2023\u725b\u5ba2\u5bd2\u5047\u7b97\u6cd5\u57fa\u7840\u96c6\u8bad\u84252 L-Tokitsukaze and Three Integers solution \u6211\u4eec\u5148\u6765\u5206\u6790\u4e00\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u5bfb\u627e\u4e09\u4e2a\u6570\uff0c\u7136\u540e\u6ee1\u8db3\u4e00\u5b9a\u7684\u6761\u4ef6\uff0c\u7531\u4e8en=5000,n\u7684\u4e09\u6b21\u65b9\u7684\u590d\u6742\u5ea6\u80af\u5b9a\u662f\u4e0d\u53ef\u53d6\u7684\uff0c\u6211\u4eec\u5c31\u5f97\u60f3\u529e\u6cd5\u4f18\u5316\u5e38\u6570\u3002 1.\u7b2c\u4e00\u6b21\u7684\u9519\u8bef\u5c1d\u8bd5\uff0c\u4f7f\u7528vector&lt;pair&lt;int, pair&lt;int, int&gt;&gt;&gt;\uff0c\u7b2c\u4e00\u7ef4\u5ea6\u5b58\u653ea[i] a[j] % mod\uff0c\u7b2c\u4e8c\u7ef4\u5ea6\u5b58\u653ei,j,\u7136\u540e\u518d\u679a\u4e3ea[i]\uff0c\u7528f[(a[i] a[j] % mod + a[i] % mod) % mod]++,\u6765\u5b58\u653e5000\u4ee5\u5185\u7684i\u7b49\u4e8e\u65f6\u7684\u7b54\u6848\uff0c\u6700\u540e\u518d\u5c06f[i]\u51cf\u53bb\uff08a[i] a[j] + a[i]\u548ca[i] a[j] + a[j])\u8fd9\u79cd\u60c5\u51b5\u3002\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u57fa\u672c\u548c\u66b4\u529b\u6ca1\u5565\u533a\u522b\uff0c\u5c5e\u4e8e\u8131\u88e4\u5b50\u653e\u5c41\u4e86\u3002 2.\u7b2c\u4e8c\u6b21\u5c1d\u8bd5\uff0c\u6211\u4eec\u6362\u4e2a\u601d\u8def\uff0caiaj\u6ca1\u529e\u6cd5\u538b\u7f29\uff08ps.\u521a\u5f00\u59cb\u6ca1\u60f3\u5230\u538b\u7f29\u8fd9\u4e2a\uff09\uff0c\u6211\u4eec\u5c31\u538b\u7f29a[i],\u6211\u4eec\u5c06a[i] % mod\uff0c\u5b58\u653e\u5230b[i]\u91cc\u9762\uff0c\u8ba1\u7b97a[i] % mod\u540e\u76f8\u540c\u7684\u6570\u76ee\uff0c\u6700\u540e\u518d\u5c06(a[i] a[j] % mod + i % mod) % mod\u7684\u6570\u76ee\u8ba1\u7b97\u51fa\u6765\u5c31\u53ef\u4ee5\u4e86\uff0c\u518d\u51cf\u53bba[i] a[j] + a[i]\u548ca[i] a[j] + a[j])\u8fd9\u79cd\u60c5\u51b5\u3002\u8fd9\u79cd\u60c5\u51b5\u4f18\u5316\u4e86\u4e00\u90e8\u5206\uff0c\u4f46\u662f\u4f18\u5316\u7a0b\u5ea6\u8fd8\u662f\u4e0d\u591f\uff0c\u5982\u679ca[i] % mod\uff0c\u4f46\u662fmod ==5000 == n\u90a3\u5c31\u76f8\u5f53\u4e8e\u6ca1\u6709\u4f18\u5316\u3002\u4e8e\u662f\u6211\u4eec\u5c06\u77db\u5934\u8f6c\u5411\u4f18\u5316a[i] a[j] 3.\u4e8e\u662f\u6709\u4e86\u89e3\u6cd5\u4e09\uff0c\u6211\u4eec\u5c06b[a[i] [&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":[5,11,9],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-solution","tag-5","tag-11","tag-9"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/19","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=19"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}