{"id":997,"date":"2014-10-02T08:17:58","date_gmt":"2014-10-02T00:17:58","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=997"},"modified":"2014-10-02T08:17:58","modified_gmt":"2014-10-02T00:17:58","slug":"hdu-3507-print-article","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/hdu-3507-print-article\/","title":{"rendered":"HDU 3507. Print Article"},"content":{"rendered":"<p><!--more--><\/p>\n<h3>Brief description: <\/h3>\n<p>\u7565\u3002\uff09<\/p>\n<h3>Analysis: <\/h3>\n<p>\uff08\u53c8\u6ca1 Ci \u7684\u6570\u636e\u8303\u56f4\u3002\uff09<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(5e5) + 9;\r\nLL f&#x5B;N], C&#x5B;N]; int q&#x5B;N], cz, op;\r\nint n, m;\r\n\r\n#define k (-2*C&#x5B;i])\r\n#define x(j) (C&#x5B;j])\r\n#define y(j) (f&#x5B;j] + sqr(x(j)))\r\n#define eval(j) (k*x(j) + y(j))\r\n\r\nLL det(LL x1, LL y1, LL x2, LL y2){\r\n    return x1*y2 - x2*y1;\r\n}\r\nint dett(int p0, int p1, int p2){\r\n    LL t = det(x(p1)-x(p0), y(p1)-y(p0), x(p2)-x(p0), y(p2)-y(p0));\r\n    return t &lt; 0 ? -1 : t &gt; 0;\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    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    while (~scanf(&quot;%d %d&quot;, &amp;n, &amp;m)){\r\n\r\n        REP_1(i, n) C&#x5B;i] = C&#x5B;i-1] + RD();\r\n\r\n        cz = 0, op = 0; REP_1(i, n){\r\n            while (cz &lt; op &amp;&amp; eval(q&#x5B;cz]) &gt;= eval(q&#x5B;cz+1])) ++cz; f&#x5B;i] = m + sqr(C&#x5B;i]) + eval(q&#x5B;cz]);\r\n            while (cz &lt; op &amp;&amp; dett(q&#x5B;op-1], q&#x5B;op], i) &lt;= 0) --op; q&#x5B;++op] = i;\r\n        }\r\n\r\n        OT(f&#x5B;n]);\r\n    }\r\n}\r\n<\/pre>\n<p><a href=\"http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2801203\">http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2801203<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_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","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-997","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-g5","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/997","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=997"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/997\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}