{"id":124,"date":"2026-04-16T16:40:28","date_gmt":"2026-04-16T08:40:28","guid":{"rendered":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/?p=124"},"modified":"2026-04-16T16:40:28","modified_gmt":"2026-04-16T08:40:28","slug":"%e6%a0%91%e7%8a%b6%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/2026\/04\/16\/%e6%a0%91%e7%8a%b6%e6%95%b0%e7%bb%84\/","title":{"rendered":"\u6811\u72b6\u6570\u7ec4"},"content":{"rendered":"\n<p>\u89c6\u9891\u8bb2\u89e3: <a href=\"https:\/\/www.bilibili.com\/video\/BV1WDrnBPEKN\/?spm_id_from=333.337.search-card.all.click&amp;vd_source=0d24edb3ad1a435dd9fec2b4bace6d95\">https:\/\/www.bilibili.com\/video\/BV1WDrnBPEKN\/<\/a><\/p>\n\n\n\n<p>\u7ef4\u57fa\u767e\u79d1: <a href=\"https:\/\/oi-wiki.org\/ds\/fenwick\/#thetan-%E5%BB%BA%E6%A0%91\">https:\/\/oi-wiki.org\/ds\/fenwick\/#thetan-%E5%BB%BA%E6%A0%91<\/a><\/p>\n\n\n\n<p>\u4f8b\u9898: <a href=\"https:\/\/www.luogu.com.cn\/problem\/P3374\">https:\/\/www.luogu.com.cn\/problem\/P3374<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;algorithm>\n#include &lt;cstring>\n#include &lt;stack>\n#include &lt;cmath>\n#include &lt;vector>\n#include &lt;queue>\n#include &lt;climits>\n\nusing namespace std;\ntypedef long long ll;\n\nint n, m, a&#91;600000], c&#91;600000]; \n\n\/\/ \u8ba1\u7b97lowbit\nint lowbit(int x) {\n    return x &amp; (-x);\n}\n\n\/\/ \u8ba1\u7b97\u524d\u7f00\u548c\nint query(int x) {\n    int ans = 0;\n    while (x > 0) {\n        ans += c&#91;x];\n        x -= lowbit(x);\n    }\n    return ans;\n}\n\n\/\/ \u4ece\u5f53\u524d\u4f4d\u7f6e\u4f9d\u6b21\u5411\u540e\u52a0x\nvoid change(int pos, int delta) {\n    while (pos &lt;= n) {\n        c&#91;pos] += delta;\n        pos += lowbit(pos);\n    }\n}\n\nint main() {\n    cin >> n >> m;\n    for (int i = 1; i &lt;= n; i++) cin >> a&#91;i];\n\n    \/\/ O(n) \u5efa\u6811\n    for (int i = 1; i &lt;= n; i++) {\n        c&#91;i] += a&#91;i];\n        int j = lowbit(i) + i;\n        if (j &lt;= n) c&#91;j] += c&#91;i];\n    }\n\n    for (int i = 1; i &lt;= m; i++) {\n        int tp, x, y;\n        cin >> tp >> x >> y;\n        if (tp == 1) {\n            change(x, y); \/\/ \u5c06\u4f4d\u7f6e x \u589e\u52a0 y\n        } else if (tp == 2) {\n            \/\/ \u533a\u95f4\u548c = \u524d\u7f00\u548c(y) - \u524d\u7f00\u548c(x-1)\n            cout &lt;&lt; query(y) - query(x - 1) &lt;&lt; endl;\n        }\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u89c6\u9891\u8bb2\u89e3: https:\/\/w&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":1,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":125,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/124\/revisions\/125"}],"wp:attachment":[{"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}