{"id":35,"date":"2009-11-19T16:47:00","date_gmt":"2009-11-19T08:47:00","guid":{"rendered":"http:\/\/localhost\/?p=35"},"modified":"2009-11-19T16:47:00","modified_gmt":"2009-11-19T08:47:00","slug":"spoj_gss1-3","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=35","title":{"rendered":"SPOJ GSS1-3"},"content":{"rendered":"\n<p>\u7ebf\u6bb5\u6811\u7ec3\u4e60\u9898\u5566\u3002\u3002\u3002<\/p>\n<p>\u90fd\u5f88\u6c34\u7684\u6837\u5b50\u3002\u3002\u4e0d\u8fc7\u7531\u4e8e\u6211\u76f4\u63a5\u5199\u6307\u9488\u4e86\u3002\u3002\u901f\u5ea6\u5b9e\u5728\u662f\u3002\u3002\u3002<\/p>\n<p>1&#8230;<\/p>\n<p>#include&lt;iostream&gt;#define REP(i,n) for(int i=0;i&lt;n;i++)#define Renew(x,c)x=max(x,c)using namespace std;typedef long long LL;const int maxn=60000,maxv=maxn*4,inf=~0U&gt;&gt;2;int A[maxn],n;struct Tree{       LL Max,Lmax,Rmax,Sum;       Tree(){}       Tree(int M,int L,int R,int S):Max(M),Lmax(L),Rmax(R),Sum(S){Lch=Rch=0;}       Tree* Lch,*Rch;           }*root;inline void Update(Tree*F,Tree*Lch,Tree*Rch){     F-&gt;Sum=Lch-&gt;Sum+Rch-&gt;Sum;     F-&gt;Lmax=max(Lch-&gt;Lmax,Lch-&gt;Sum+Rch-&gt;Lmax);     F-&gt;Rmax=max(Rch-&gt;Rmax,Rch-&gt;Sum+Lch-&gt;Rmax);     F-&gt;Max=max(max(Lch-&gt;Max,Rch-&gt;Max),Lch-&gt;Rmax+Rch-&gt;Lmax);}Tree* build(int l,int r){   if(l==r) return new Tree(A[l],A[l],A[l],A[l]);   Tree* now=new Tree;   int mid=(l+r)\/2;   now-&gt;Lch=build(l,mid);now-&gt;Rch=build(mid+1,r);   Update(now,now-&gt;Lch,now-&gt;Rch);   return now;}Tree* ask(Tree*T,int l,int r,int first,int last){      if(l==first&amp;&amp;r==last)        return T;      int mid=(l+r)\/2;      if(first&gt;mid) return ask(T-&gt;Rch,mid+1,r,first,last);      if(last&lt;=mid) return ask(T-&gt;Lch,l,mid,first,last);      Tree* ans=new Tree;      Update(ans,ask(T-&gt;Lch,l,mid,first,mid),ask(T-&gt;Rch,mid+1,r,mid+1,last));      return ans;}int main(){         cin&gt;&gt;n;         REP(i,n) scanf(&quot;%d&quot;,A+i);     root=build(0,n-1);     int q,s,t;cin&gt;&gt;q;         REP(i,q)     {                  scanf(&quot;%d %d&quot;,&amp;s,&amp;t);s=max(s,1);t=min(t,n);            <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/printf.html\">printf<\/a>(&quot;%lldn&quot;,ask(root,0,n-1,s-1,t-1)-&gt;Max);     }           }4.1s&#8230;\u8fd9\u901f\u5ea6\u3002\u3002\u3002 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ebf\u6bb5\u6811\u7ec3\u4e60\u9898\u5566\u3002\u3002\u3002 \u90fd\u5f88\u6c34\u7684\u6837\u5b50\u3002\u3002\u4e0d\u8fc7\u7531\u4e8e\u6211\u76f4\u63a5\u5199\u6307\u9488\u4e86\u3002\u3002\u901f\u5ea6\u5b9e\u5728\u662f\u3002\u3002\u3002 1&#8230; #include&lt;iostream&gt;#define REP(i,n) for(int i=0;i&lt;n;i++)#define Renew(x,c)x=max(x,c)using namespace std;typedef long long LL;const int maxn=60000,maxv=maxn*4,inf=~0U&gt;&gt;2;int A[maxn],n;struct Tree{ LL Max,Lmax,Rmax,Sum; Tree(){} Tree(int M,int L,int R,int S):Max(M),Lmax(L),Rmax(R),Sum(S){Lch=Rch=0;} Tree* Lch,*Rch; }*root;inline void Update(Tree*F,Tree*Lch,Tree*Rch){ F-&gt;Sum=Lch-&gt;Sum+Rch-&gt;Sum; F-&gt;Lmax=max(Lch-&gt;Lmax,Lch-&gt;Sum+Rch-&gt;Lmax); F-&gt;Rmax=max(Rch-&gt;Rmax,Rch-&gt;Sum+Lch-&gt;Rmax); F-&gt;Max=max(max(Lch-&gt;Max,Rch-&gt;Max),Lch-&gt;Rmax+Rch-&gt;Lmax);}Tree* build(int l,int r){ if(l==r) return new Tree(A[l],A[l],A[l],A[l]); Tree* now=new Tree; int mid=(l+r)\/2; now-&gt;Lch=build(l,mid);now-&gt;Rch=build(mid+1,r); Update(now,now-&gt;Lch,now-&gt;Rch); return now;}Tree* ask(Tree*T,int l,int r,int first,int last){ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/35"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}