{"id":1996,"date":"2022-07-21T01:06:53","date_gmt":"2022-07-20T17:06:53","guid":{"rendered":"https:\/\/www.shuizilong.com\/house\/?p=1996"},"modified":"2022-07-21T02:35:16","modified_gmt":"2022-07-20T18:35:16","slug":"atl-%e9%a3%8e-splay-%e6%a8%a1%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/atl-%e9%a3%8e-splay-%e6%a8%a1%e6%9d%bf\/","title":{"rendered":"atl \u98ce splay \u6a21\u677f"},"content":{"rendered":"<p>\u5f04\u5b8c\u4e86\u4e00\u4e2a\u7248\u672c\u611f\u89c9\u8fd8\u884c<br \/>\n<a href=\"https:\/\/github.com\/lychees\/last-weapon\/commit\/58976a70bc0948c2073091c6cf2966a16e352127\">https:\/\/github.com\/lychees\/last-weapon\/commit\/58976a70bc0948c2073091c6cf2966a16e352127<\/a><\/p>\n<p>\u76ee\u524d\u4f8b\u9898\u7528\u7684\u662f GSS \u7cfb\u5217\u3002\u3002\u3002<\/p>\n<p>\u4e0d\u8fc7 GSS3 \u8fd9\u4e2a\u9898\u548c GSS1 \u4e00\u6837\u90fd\u5361\u4ee3\u7801\u957f\u5ea6\u3002\u3002\u9700\u8981\u5220\u70b9\u4e1c\u897f\u3002\u3002<br \/>\nGSS6 \u5012\u662f\u5f88\u9002\u5408\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;lastweapon\/segtree&gt;\r\nusing namespace lastweapon;\r\n\r\nstruct rec{\r\n    int ss, ls, rs, ms;\r\n    rec(int s = 0) {\r\n        ss = ls = rs = ms = s;\r\n    }\r\n};\r\n\r\nrec e() {\r\n    rec z = rec(-INF);\r\n    z.ss = 0;\r\n    return z;\r\n}\r\n\r\nrec op(const rec l, const rec r) {\r\n    rec z;\r\n    z.ss = l.ss + r.ss;\r\n    z.ls = max(l.ls, l.ss + r.ls);\r\n    z.rs = max(r.rs, l.rs + r.ss);\r\n    z.ms = max({l.ms, r.ms, l.rs + r.ls});\r\n    return z;\r\n}\r\n\r\nint main() {\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n#endif\r\n    int n; RD(n); vector&lt;rec&gt; a(n); REP(i, n) a&#x5B;i] = rec(RD());\r\n    segtree&lt;rec, op, e&gt; T(a);\r\n\r\n    Rush {\r\n        if (RD()) { \/\/ query\r\n            int l, r; RD(l, r); --l;\r\n            cout &lt;&lt; T.prod(l, r).ms &lt;&lt; endl;\r\n        } else { \/\/ modify\r\n            int x, y; RD(x, y); --x;\r\n            T.set(x, rec(y));\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;lastweapon\/splay&gt;\r\n\r\nstruct rec{\r\n    int ky, ss, ls, rs, ms;\r\n    rec(int s = 0) {\r\n        ky = ss = ls = rs = ms = s;\r\n    }\r\n};\r\n\r\nrec e() {\r\n    rec z = rec(-INF);\r\n    z.ss = 0;\r\n    return z;\r\n}\r\n\r\nvoid op(rec&amp; x, const rec l, const rec r) {\r\n    x.ss = l.ss + x.ky + r.ss;\r\n    x.ls = max(l.ls, l.ss + x.ky + max(0, r.ls));\r\n    x.rs = max(r.rs, max(0, l.rs) + x.ky + r.ss);\r\n    x.ms = max({l.ms, max(l.rs, 0) + x.ky + max(0, r.ls), r.ms});\r\n}\r\n\r\nint main() {\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n#endif\r\n    int n; RD(n); vector&lt;rec&gt; a(n); REP(i, n) a&#x5B;i] = rec(RD());\r\n    lastweapon::splay::splay&lt;rec, op, e&gt; T(a);\r\n\r\n    Rush {\r\n        if (RD()) { \/\/ query\r\n            int l, r; RD(l, r); ++r;\r\n            cout &lt;&lt; T.prod(l, r).ms &lt;&lt; endl;\r\n        } else { \/\/ modify\r\n            int x, y; RD(x, y);\r\n            T.set(x, rec(y));\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;algorithm&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;cstring&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;string&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;bitset&gt;\r\n#include &lt;queue&gt;\r\n#include &lt;cmath&gt;\r\n#include &lt;ctime&gt;\r\n#include &lt;list&gt;\r\n#include &lt;set&gt;\r\n#include &lt;map&gt;\r\n\r\nusing namespace std;\r\n\r\n#define REP(i, n) for (int i=0;i&lt;int(n);++i)\r\n#define Rush for(int ____T=RD(); ____T--;)\r\n\r\nconst int INF = 0x3f3f3f3f;\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;);\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;);\r\ninline int RD(){ int x; RD(x); return x;}\r\ntemplate&lt;class T0, class T1&gt; inline void RD(T0 &amp;x0, T1 &amp;x1){RD(x0), RD(x1);}\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;x){\r\n    scanf(&quot;%d&quot;, &amp;x);\r\n}\r\n\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;x){\r\n    printf(&quot;%d\\n&quot;, x);\r\n}\r\n\r\n\/* .................................................................................................................................. *\/\r\n\r\n\r\nnamespace lastweapon {\r\n\r\nnamespace splay {\r\n\r\ntemplate &lt;class S, void (*op)(S&amp;, const S, const S), S (*e)()&gt;\r\nstruct node {\r\n\r\n    static node *NIL; node *c&#x5B;2], *p;\r\n    int sz; S d;\r\n\r\n#define NIL node::NIL\r\n#define l c&#x5B;0]\r\n#define r c&#x5B;1]\r\n#define lx x-&gt;l\r\n#define rx x-&gt;r\r\n#define px x-&gt;p\r\n#define ly y-&gt;l\r\n#define ry y-&gt;r\r\n#define py y-&gt;p\r\n\r\n    node() {\r\n        d=e();\r\n    }\r\n\r\n    inline void reset(S s){l=r=p=NIL,d=s;sz=1;}\r\n\r\n    inline void upd(){\r\n        sz = l-&gt;sz + 1 + r-&gt;sz;\r\n        op(d, l-&gt;d, r-&gt;d);\r\n    }\r\n    inline int sgn(){return p-&gt;r==this;}\r\n    inline void setc(int d,node*x){c&#x5B;d]=x,px=this;}\r\n    inline void setl(node*x){setc(0,x);}\r\n    inline void setr(node*x){setc(1,x);}\r\n\r\n    inline void rot(int d){\r\n        node*y=p,*z=py;z-&gt;setc(y-&gt;sgn(),this);\r\n        y-&gt;setc(d,c&#x5B;!d]),setc(!d,y),y-&gt;upd();\r\n    }\r\n    inline void rot(){rot(sgn());}\r\n    inline node*splay(node*t){\r\n        int a,b;while(p!=t){\r\n            if (p-&gt;p==t){rot();break;}\r\n            else a=sgn(),b=p-&gt;sgn(),(a^b?this:p)-&gt;rot(a),rot(b);\r\n        }\r\n        upd();\r\n        return this;\r\n    }\r\n};\r\n\r\n\r\n#undef NIL\r\n\r\ntemplate &lt;class S, void (*op)(S&amp;, const S, const S), S (*e)()&gt;\r\nnode&lt;S, op, e&gt; *node&lt;S, op, e&gt;::NIL = new node&lt;S, op, e&gt;;\r\n\r\n\r\ntemplate &lt;class S, void (*op)(S&amp;, const S, const S), S (*e)()&gt; struct splay {\r\n\r\n    using nod = node&lt;S, op, e&gt;;\r\n\r\n    std::vector&lt;nod&gt; d;\r\n    int n; nod* rt;\r\n\r\n    splay() : splay(0) {}\r\n    explicit splay(int n) : splay(std::vector&lt;S&gt;(n, e())) {}\r\n    explicit splay(const std::vector&lt;S&gt;&amp; a) : n(int(a.size())) {\r\n        rt = new nod(); rt-&gt;reset(0);\r\n        REP(i, n) {\r\n            nod* t = new nod();\r\n            t-&gt;reset(a&#x5B;i]);\r\n            t-&gt;setl(rt); t-&gt;upd();\r\n            rt = t;\r\n        }\r\n        nod* t = new nod();\r\n        t-&gt;reset(0);\r\n        t-&gt;setl(rt); t-&gt;upd();\r\n        rt = t;\r\n    }\r\n\r\n    nod *select(int k, nod*t=nod::NIL){\r\n        nod *x = rt; while (lx-&gt;sz != k){\r\n            if (k &lt; lx-&gt;sz) x = lx;\r\n            else k -= lx-&gt;sz+1, x = rx;\r\n        }\r\n\r\n        if (t == nod::NIL) rt = x;\r\n        return x-&gt;splay(t);\r\n    }\r\n\r\n    nod *select(int a, int b){\r\n        return select(a-1, select(b))-&gt;r;\r\n    }\r\n\r\n    S prod(int a, int b) {\r\n        return select(a, b)-&gt;d;\r\n    }\r\n\r\n    void set(int p, S s) {\r\n        nod* x = select(p, p+1); x-&gt;d = s;\r\n\r\n        while (x-&gt;p != nod::NIL) {\r\n            x = x-&gt;p;\r\n            x-&gt;upd();\r\n        }\r\n    }\r\n};\r\n\r\n#undef l\r\n#undef rgu\r\n\r\n\r\n}  \/\/ namespace splay\r\n\r\n}  \/\/ namespace lastweapon\r\n\r\n\r\nstruct rec{\r\n    int ky, ss, ls, rs, ms;\r\n    rec(int s = 0) {\r\n        ky = ss = ls = rs = ms = s;\r\n    }\r\n};\r\n\r\nrec e() {\r\n    rec z = rec(-INF);\r\n    z.ss = 0;\r\n    return z;\r\n}\r\n\r\nvoid op(rec&amp; x, const rec l, const rec r) {\r\n    x.ss = l.ss + x.ky + r.ss;\r\n    x.ls = max(l.ls, l.ss + x.ky + max(0, r.ls));\r\n    x.rs = max(r.rs, max(0, l.rs) + x.ky + r.ss);\r\n    x.ms = max({l.ms, max(l.rs, 0) + x.ky + max(0, r.ls), r.ms});\r\n}\r\n\r\nint main() {\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n#endif\r\n    int n; RD(n); vector&lt;rec&gt; a(n); REP(i, n) a&#x5B;i] = rec(RD());\r\n    lastweapon::splay::splay&lt;rec, op, e&gt; T(a);\r\n\r\n    Rush {\r\n        if (RD()) { \/\/ query\r\n            int l, r; RD(l, r); ++r;\r\n            cout &lt;&lt; T.prod(l, r).ms &lt;&lt; endl;\r\n        } else { \/\/ modify\r\n            int x, y; RD(x, y);\r\n            T.set(x, rec(y));\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5f04\u5b8c\u4e86\u4e00\u4e2a\u7248\u672c\u611f\u89c9\u8fd8\u884c https:\/\/github.com\/lychees\/last-weapon\/commit\/58976a70bc0948c2073091c6cf2966a16e352127 \u76ee\u524d\u4f8b\u9898\u7528\u7684\u662f GSS \u7cfb\u5217\u3002\u3002\u3002 \u4e0d\u8fc7 GSS3 \u8fd9\u4e2a\u9898\u548c GSS1 \u4e00\u6837\u90fd\u5361\u4ee3\u7801\u957f\u5ea6\u3002\u3002\u9700\u8981\u5220\u70b9\u4e1c\u897f\u3002\u3002 GSS6 \u5012\u662f\u5f88\u9002\u5408\u3002\u3002\u3002 #include &lt;lastweapon\/segtree&gt; using namespace lastweapon; struct rec{ int ss, ls, rs, ms; rec(int s = 0) { ss = ls = rs = ms = s; } }; rec e() { rec z = rec(-INF); z.ss = 0; return z; } rec op(const [&hellip;]<\/p>\n","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-1996","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-wc","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1996","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=1996"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1996\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}