{"id":371,"date":"2018-11-08T13:27:18","date_gmt":"2018-11-08T05:27:18","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=371"},"modified":"2018-11-08T14:51:15","modified_gmt":"2018-11-08T06:51:15","slug":"lp1471-%e6%96%b9%e5%b7%ae","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2018\/11\/08\/lp1471-%e6%96%b9%e5%b7%ae\/","title":{"rendered":"lp1471 \u65b9\u5dee"},"content":{"rendered":"<p>\u5927\u529b\u4e0a\u4e00\u4e2a\u7ebf\u6bb5\u6811\u3002<br \/>\n\u5c06\u65b9\u5dee\u5c55\u5f00\u4e3a\u7531\u533a\u95f4\u5e73\u65b9\u7684\u548c\u4e0e\u533a\u95f4\u548c\u4e24\u9879\u6784\u6210\u7684\u591a\u9879\u5f0f\uff0c\u7136\u540e\u7ef4\u62a4\u533a\u95f4\u5e73\u65b9\u7684\u548c\u4e0e\u533a\u95f4\u548c\u3002<br \/>\n\u5177\u4f53\u6765\u8bf4\uff0c\u901a\u8fc7\u5c06\u4e8c\u9879\u5f0f\u5c55\u5f00\u53ef\u4ee5\u5f97\u5230\u516c\u5f0f\uff1a<br \/>\n$$ \\sum_{i=l}^{r}(a_{i}+k)^2=\\sum_{i=l}^{r}a_{i}^2+\\sum_{i=l}^{r}*k*2+(r-l+1)*k^2 $$<br \/>\n\u5957\u7528\u8fd9\u4e2a\u516c\u5f0f\uff0c\u5c31\u53ef\u4ee5\u7528\u4e0e\u7ef4\u62a4\u666e\u901a\u7684\u7ebf\u6bb5\u6811\u76f8\u4f3c\u7684\u65b9\u6cd5\u6765\u7ef4\u62a4\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"cpp\">#include&lt;iostream&gt;\r\n#include&lt;cstdio&gt;\r\nusing namespace std;\r\n#define LEN (R-L+1)\r\n#define MID ((L+R)&gt;&gt;1)\r\n#define LLEN (MID-L+1)\r\n#define RLEN (R-MID)\r\n#define LS (X&lt;&lt;1)\r\n#define RS (X&lt;&lt;1|1)\r\nstruct data{\r\n\tdouble sm;\r\n\tdouble sm2;\r\n\tdouble lzy;\r\n}tr[270005];\/\/262141\r\ninline void rnw(int X,int Len,double K){\r\n\ttr[X].sm2+=(tr[X].sm*2*K+K*K*Len);\r\n\ttr[X].sm+=(K*Len);\r\n\ttr[X].lzy+=K;\r\n}\r\ninline void pshd(int X,int L,int R){\r\n\trnw(LS,LLEN,tr[X].lzy);rnw(RS,RLEN,tr[X].lzy);\r\n\ttr[X].lzy=0;\r\n}\r\ninline void updt(int X){\r\n\ttr[X].sm2=tr[LS].sm2+tr[RS].sm2;\r\n\ttr[X].sm=tr[LS].sm+tr[RS].sm;\r\n}\r\ninline void add(int X,int L,int R,int A,int B,double K){\r\n\tif(L&gt;=A&amp;&amp;R&lt;=B){\r\n\t\trnw(X,LEN,K);\r\n\t\treturn;\r\n\t}\r\n\tpshd(X,L,R);\r\n\tif(A&lt;=MID){\r\n\t\tadd(LS,L,MID,A,B,K);\r\n\t}\r\n\tif(B&gt;MID){\r\n\t\tadd(RS,MID+1,R,A,B,K);\r\n\t}\r\n\tupdt(X);\r\n}\r\ninline double qrySm(int X,int L,int R,int A,int B){\r\n\tif(L&gt;=A&amp;&amp;R&lt;=B){\r\n\t\treturn tr[X].sm;\r\n\t}\r\n\tpshd(X,L,R);\r\n\tdouble rt=0;\r\n\tif(A&lt;=MID){\r\n\t\trt+=qrySm(LS,L,MID,A,B);\r\n\t}\r\n\tif(B&gt;MID){\r\n\t\trt+=qrySm(RS,MID+1,R,A,B);\r\n\t}\r\n\treturn rt;\r\n}\r\ninline double qrySm2(int X,int L,int R,int A,int B){\r\n\tif(L&gt;=A&amp;&amp;R&lt;=B){\r\n\t\treturn tr[X].sm2;\r\n\t}\r\n\tpshd(X,L,R);\r\n\tdouble rt=0;\r\n\tif(A&lt;=MID){\r\n\t\trt+=qrySm2(LS,L,MID,A,B);\r\n\t}\r\n\tif(B&gt;MID){\r\n\t\trt+=qrySm2(RS,MID+1,R,A,B);\r\n\t}\r\n\treturn rt;\r\n}\r\nint n,m;\r\ndouble a[100005];\r\ninline void build(int X,int L,int R){\r\n\tif(L==R){\r\n\t\ttr[X].sm=a[L];\r\n\t\ttr[X].sm2=a[L]*a[R];\r\n\t\treturn;\r\n\t}\r\n\tbuild(LS,L,MID);build(RS,MID+1,R);\r\n\tupdt(X);\r\n}\r\nvoid init(){\r\n\tscanf(\"%d%d\",&amp;n,&amp;m);\r\n\tdouble x;\r\n\tfor(int i=1;i&lt;=n;++i){\r\n\t\tscanf(\"%lf\",a+i);\r\n\t}\r\n\tbuild(1,1,n);\r\n\tint op,l,r;\r\n\twhile(m--){\r\n\t\tscanf(\"%d%d%d\",&amp;op,&amp;l,&amp;r);\r\n\t\tif(op==1){\r\n\t\t\tscanf(\"%lf\",&amp;x);\r\n\t\t\tadd(1,1,n,l,r,x);\r\n\t\t}else if(op==2){\r\n\t\t\tprintf(\"%.4lf\\n\",qrySm(1,1,n,l,r)\/(r-l+1));\r\n\t\t}else{\r\n\t\t\tx=qrySm(1,1,n,l,r);\r\n\t\t\tprintf(\"%.4lf\\n\",(qrySm2(1,1,n,l,r)-x*x\/(r-l+1))\/(r-l+1));\r\n\t\t}\r\n\t}\r\n}\r\nint main(){\r\n\tinit();\r\n\treturn 0;\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u529b\u4e0a\u4e00\u4e2a\u7ebf\u6bb5\u6811\u3002 \u5c06\u65b9\u5dee\u5c55\u5f00\u4e3a\u7531\u533a\u95f4\u5e73\u65b9\u7684\u548c\u4e0e\u533a\u95f4\u548c\u4e24\u9879\u6784\u6210\u7684\u591a\u9879\u5f0f\uff0c\u7136\u540e\u7ef4\u62a4\u533a\u95f4\u5e73\u65b9\u7684\u548c\u4e0e\u533a\u95f4\u548c\u3002 \u5177\u4f53\u6765 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2018\/11\/08\/lp1471-%e6%96%b9%e5%b7%ae\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp1471 \u65b9\u5dee\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,43,8,6,48,5],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/371"}],"collection":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/comments?post=371"}],"version-history":[{"count":2,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/371\/revisions"}],"predecessor-version":[{"id":373,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/371\/revisions\/373"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}