{"id":301,"date":"2022-08-12T00:02:50","date_gmt":"2022-08-11T16:02:50","guid":{"rendered":"https:\/\/blog.cirno.fun\/?p=301"},"modified":"2024-09-12T09:35:56","modified_gmt":"2024-09-12T01:35:56","slug":"%e4%ba%8c%e7%bb%b4%e5%89%8d%e7%bc%80%e5%92%8c-%e6%af%94%e6%83%b3%e8%b1%a1%e4%b8%ad%e7%9a%84%e7%ae%80%e5%8d%95","status":"publish","type":"post","link":"https:\/\/blog.sssn.tech\/?p=301","title":{"rendered":"\u4e8c\u7ef4\u524d\u7f00\u548c\u2014\u2014\u6bd4\u60f3\u8c61\u4e2d\u7684\u7b80\u5355"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/1.jpg\" alt=\"\" \/>\u770b\u4e00\u4e0b\u9898\u5148 <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1660232782444.png\" alt=\"file\" \/>\u8fd9\u4e2aq\u592a\u5927\u4e86\uff0c\u663e\u7136\u662f\u4e0d\u80fd\u66b4\u529b\u505a \u548c\u4e00\u7ef4\u524d\u7f00\u548c\u7c7b\u4f3c\u7684\uff0c\u6211\u4eec\u5c06\u4e4b\u62d3\u5c55\u81f3\u4e8c\u7ef4\u7a7a\u95f4\uff1a\u7528\u4e8c\u7ef4\u6570\u7ec4<code>s[i][j]<\/code>\u6765\u8868\u793a\u4ece(1,1)\u81f3(i,j)\u7684\u77e9\u9635\u4e2d\u6240\u6709\u5143\u7d20\u7684\u548c<\/p>\n<p>\u6211\u4e60\u60ef\u7528Excel\u6765\u6a21\u62df\u8fd9\u4e2a\u8fc7\u7a0b <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1660233213870.png\" alt=\"file\" \/>\u5f53\u6211\u4eec\u8bfb\u5165<code>a[i][j]<\/code>\u65f6\uff0c<code>s[i][j]=s[i][j-1]+s[i-1][j]-s[i-1][j-1]<\/code>\uff0c\u4e0d\u96be\u770b\u51fa\u7ef4\u62a4s\u6570\u7ec4\u7684\u8fc7\u7a0b\u662f\u53ef\u4ee5\u548c\u8bfb\u5165\u540c\u65f6\u8fdb\u884c\u7684<\/p>\n<pre><code class=\"language-cpp\">int n,m,q;\ncin&gt;&gt;n&gt;&gt;m&gt;&gt;q;\nfor(int i=1;i&lt;=n;i++)\n    for(int j=1;j&lt;=m;j++){\n        cin&gt;&gt;a[i][j];\n        s[i][j]=s[i][j-1]+s[i-1][j]+a[i][j]-s[i-1][j-1];\n    }<\/code><\/pre>\n<p>\u4e0b\u4e00\u6b65\u662f\u5904\u7406\u67e5\u8be2\u5750\u6807(x1,y1),(x2,y2) \u4e24\u4e2a\u70b9\u7684\u5206\u5e03\u4e0d\u786e\u5b9a\uff0c\u6211\u4eec\u5e0c\u671b\u70b91\u4f4d\u4e8e\u5de6\u4e0a\u89d2\uff0c\u70b92\u4f4d\u4e8e\u53f3\u4e0b\u89d2\uff0c\u56e0\u6b64<\/p>\n<pre><code class=\"language-cpp\">cin&gt;&gt;x1&gt;&gt;y1&gt;&gt;x2&gt;&gt;y2;\nif(x1&gt;x2)\n    swap(x1,x2);\nif(y1&gt;y2)\n    swap(y1,y2);<\/code><\/pre>\n<p>ACwing\u7684\u6570\u636e\u4e2d\u7ed9\u51fa\u7684\u6570\u636e\u9ed8\u8ba4\u4e86\u8fd9\u4e2a\u539f\u5219\uff0c\u4f46\u662f\u9898\u5e72\u4e2d\u5e76\u6ca1\u6709\u63d0\u5230\uff0c\u6240\u4ee5\u6211\u505a\u7684\u65f6\u5019\u591a\u60f3\u4e86\u4e00\u6b65<\/p>\n<p>\u7136\u540e\u5904\u7406\u70b91,2\u8868\u793a\u7684\u77e9\u5f62\u4e2d\u7684\u5143\u7d20\u548c <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2022\/08\/image-1660233641245.png\" alt=\"file\" \/>\u6709\u56fe\u5c31\u5f88\u597d\u63a8\u4e86 \u8fd9\u4e2a\u77e9\u5f62\u4e2d\u7684\u5143\u7d20\u548c\u5e94\u8be5\u662f<code>s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1]<\/code>\u4e0b\u9762\u662f\u5168\u90e8\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 cout&lt;&lt;endl\nusing namespace std;\ntypedef long long ll;\n\nconst int N=1010;\nint a[N][N];\nll s[N][N];\n\nint main(){\n    ios::sync_with_stdio(false);\n    int n,m,q;\n    cin&gt;&gt;n&gt;&gt;m&gt;&gt;q;\n    for(int i=1;i&lt;=n;i++)\n        for(int j=1;j&lt;=m;j++){\n            cin&gt;&gt;a[i][j];\n            s[i][j]=s[i][j-1]+s[i-1][j]+a[i][j]-s[i-1][j-1];\n        }\n    int x1,y1,x2,y2;\n    for(int i=1;i&lt;=q;i++){\n        cin&gt;&gt;x1&gt;&gt;y1&gt;&gt;x2&gt;&gt;y2;\n        if(x1&gt;x2)\n            swap(x1,x2);\n        if(y1&gt;y2)\n            swap(y1,y2);\n        cout&lt;&lt;s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1]&lt;&lt;endl;\n    }\n\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u770b\u4e00\u4e0b\u9898\u5148 \u8fd9\u4e2aq\u592a\u5927\u4e86\uff0c\u663e\u7136\u662f\u4e0d\u80fd\u66b4\u529b\u505a \u548c\u4e00\u7ef4\u524d\u7f00\u548c\u7c7b\u4f3c\u7684\uff0c\u6211\u4eec\u5c06\u4e4b\u62d3\u5c55\u81f3\u4e8c [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-13"],"_links":{"self":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/301","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=301"}],"version-history":[{"count":1,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/301\/revisions"}],"predecessor-version":[{"id":753,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/301\/revisions\/753"}],"wp:attachment":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}