{"id":810,"date":"2013-09-03T16:04:49","date_gmt":"2013-09-03T08:04:49","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=810"},"modified":"2013-09-10T02:54:09","modified_gmt":"2013-09-09T18:54:09","slug":"spoj-9138-pyramid-sums-2","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/spoj-9138-pyramid-sums-2\/","title":{"rendered":"SPOJ 9138. Pyramid Sums 2"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>&#8230;. \u7ef4\u62a4\u4e00\u4e2a\u6570\u5217\u3002\u3002\u652f\u6301\u4ee5\u4e0b\u4e24\u4e2a\u64cd\u4f5c\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002\u8be2\u95ee\u533a\u95f4\u548c\u3002<br \/>\n\u3002\u3002\u3002\u4ee5 c \u4e3a\u4e2d\u5fc3\u5efa\u4e00\u4e2a\u5bbd\u5ea6\u4e3a w \u3002\u9ad8\u4e3a (w+1)\/2 \u7684\u7b49\u8fb9\u4e09\u89d2\u5f62\uff08w \u4e3a\u5947\u6570\uff09\u3002\u3002\u3002<br \/>\n<!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>\u505a\u6cd5 1\uff1a<a href=\"https:\/\/gist.github.com\/lychees\/6417357#file-bit-cpp\">\u7ebf\u6bb5\u6811<\/a><br \/>\n\u505a\u6cd5 2\uff1a<a href=\"https:\/\/gist.github.com\/lychees\/6417357#file-segment_tree_1-cpp\">\u4e00\u9636\u5dee\u5206\u540e\u7ebf\u6bb5\u6811\uff08\u3002\u3002\u3002\u6807\u8bb0\u66f4\u76f4\u63a5\u4e9b\u3002\u3002\u3002\uff09<\/a><br \/>\n\u505a\u6cd5 3\uff1a<a href=\"https:\/\/gist.github.com\/lychees\/6417357#file-segment_tree_2-cpp\">\u4e8c\u9636\u5dee\u5206\u540e\u76f4\u63a5\u6811\u72b6\u6570\u7ec4\u3002\u3002\u3002<\/a><\/p>\n<p>$$!\\begin{align*}\\begin{split}\\sum_{1\\leq i\\leq n}A_i &#038;= \\sum_{1\\leq i\\leq n}\\sum_{1\\leq j\\leq i}\\sum_{1\\leq k\\leq j} \\nabla^{2}  A_k \\\\ &#038;= \\sum_{1\\leq k\\leq n}\\sum_{k\\leq j\\leq n}\\sum_{j\\leq i\\leq n} \\nabla^{2} A_k \\\\ &#038;= \\sum_{1\\leq k\\leq n} \\binom{n-k+2}{2} \\nabla^{2} A_k \\\\ &#038;= \\sum_{1\\leq k\\leq n} \\frac{k^2 &#8211; (2n+3)k +(n+1)(n+2)}{2} \\nabla^{2}A_k\\end{split}\\end{align*}$$<\/p>\n<p>\u3002\u3002\u8fd9\u91cc\u3002\u3002\u6211\u4eec\u9700\u8981\u770b\u7684\u662f k \u7684\u6b21\u5e42\u524d\u9762\u7684\u7cfb\u6570\u3002\u3002\u7528\u4e09\u4e2a\u6811\u72b6\u6570\u7ec4\u5206\u522b\u7ef4\u62a4\u8fd9\u4e09\u9879\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = 1000009;\r\nconst int n = 1000000;\r\n \r\nLL S0&#x5B;N], S1&#x5B;N], S2&#x5B;N];\r\nint a, b, c, w;\r\n \r\nvoid Add(LL S&#x5B;], int x, LL d){\r\n    for (;x&lt;=n;x+=low_bit(x)) S&#x5B;x] += d;\r\n}\r\n \r\nLL Sum(LL S&#x5B;], int x){\r\n    LL z=0; for (;x;x^=low_bit(x)) z += S&#x5B;x];\r\n    return z;\r\n}\r\n \r\nvoid Add(int x, LL d){\r\n    Add(S0, x, d), Add(S1, x, d*x), Add(S2, x, d*x*x);\r\n}\r\n \r\nLL Sum(int x){\r\n    return Sum(S0, x)*(x+1)*(x+2) - Sum(S1, x)*(x*2+3) + Sum(S2, x);\r\n}\r\n \r\nvoid Add(int l, int r, LL d){\r\n    Add(l, d), Add(r+1, -d);\r\n}\r\n \r\nLL Sum(int l, int r){\r\n    return Sum(r) - Sum(l-1);\r\n}\r\n \r\nint main(){\r\n \r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n#endif\r\n \r\n    char cmd&#x5B;9]; Rush{\r\n \r\n        RS(cmd); if (cmd&#x5B;0] == 'b'){\r\n            RD(c, w), w = (w-1)\/2;\r\n            Add(c-w, c, 1), ++c, Add(c, c+w, -1); \/\/#\r\n        }\r\n        else {\r\n            RD(a, b);\r\n            OT(Sum(a, b)\/2);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>\u601d\u8003\u3002\u3002\u3002\u8003\u8651\u5982\u679c\u7ef4\u62a4\u7684\u662f\u9ad8\u9636\u7b49\u5dee\u5982\u4f55\u8fd8\u539f\u5230\u539f\u6570\u5217\u3002\u3002\u3002\u6709\u3002\u3002<\/p>\n<p>$$!\\begin{align*}\\begin{split}\\sum_{1\\leq i\\leq n} A_i &#038;= \\sum_{1\\leq i\\leq n} \\binom{n-i+k}{k} \\nabla^{k} A_i \\\\&#038;= \\sum_{1\\leq i\\leq n} \\frac{\\prod_{n+1\\leq j \\leq n+k}(j-i)}{k!} \\nabla^{k}A_i\\end{split}\\end{align*}$$<\/p>\n<p>\u3002\u3002\u3002\u6700\u540e\u4e0a\u9762\u7684\u90a3\u4e2a\u90e8\u5206\u4f3c\u4e4e\u5f88\u4e0d\u597d\u5c55\u5f00\u3002\u3002\u3002\u53ea\u80fd\u4e00\u5c42\u4e00\u5c42\u679a\u4e3e\uff1f\u3001\u3001\u3002\u3002\u3001\u3001<\/p>\n<p>&#8230;<\/p>\n<p><a href=\"http:\/\/www.spoj.com\/problems\/PYRSUM\/\">http:\/\/www.spoj.com\/problems\/PYRSUM\/<\/a><br \/>\n\u3002\u3002\u8fd9\u4e2a\u7248\u672c\u603b\u6570\u636e\u91cf\u589e\u5927\u3002\u3002\u3002\u4f46\u662f\u6bcf\u8f6e\u7684\u64cd\u4f5c\u548c\u8be2\u95ee\u53d8\u5c11\u3002\u3002\u3002\u4e0a\u9762\u53ea\u6709\u6700\u540e\u7eaf\u6811\u72b6\u6570\u7ec4\u7684\u65b9\u6cd5\u53ef\u4ee5\u8fc7\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002\u66f4\u597d\u7684\u65b9\u6cd5\u662f\u9047\u5230\u8be2\u95ee\u7684\u65f6\u5019\u3002\u3002\u76f4\u63a5\u679a\u4e3e\u4e4b\u524d\u51fa\u73b0\u7684\u6bcf\u4e2a\u64cd\u4f5c\u7d2f\u8ba1\u8d21\u732e\u3002\u3002<br \/>\n<a href=\"https:\/\/gist.github.com\/lychees\/6420822\">https:\/\/gist.github.com\/lychees\/6420822<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: &#8230;. \u7ef4\u62a4\u4e00\u4e2a\u6570\u5217\u3002\u3002\u652f\u6301\u4ee5\u4e0b\u4e24\u4e2a\u64cd\u4f5c\u3002\u3002\u3002 \u3002\u3002\u3002\u8be2\u95ee\u533a\u95f4\u548c\u3002 \u3002\u3002\u3002\u4ee5 c \u4e3a\u4e2d\u5fc3\u5efa\u4e00\u4e2a\u5bbd\u5ea6\u4e3a w \u3002\u9ad8\u4e3a (w+1)\/2 \u7684\u7b49\u8fb9\u4e09\u89d2\u5f62\uff08w \u4e3a\u5947\u6570\uff09\u3002\u3002\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[21],"tags":[],"class_list":["post-810","post","type-post","status-publish","format-standard","hentry","category-spoj"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-d4","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=810"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/810\/revisions"}],"predecessor-version":[{"id":811,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/810\/revisions\/811"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}