GSS1&GSS3

https://www.spoj.pl/problems/GSS1/

SPOJ Problem Set (classical)

1043. Can you answer these queries I

Problem code: GSS1

 

You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows:
Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y }.
Given M queries, your program must output the results of these queries.

Input

  • The first line of the input file contains the integer N.
  • In the second line, N numbers follow.
  • The third line contains the integer M.
  • M lines follow, where line i contains 2 numbers xi and yi.

Output

  • Your program should output the results of the M queries, one query per line.

Example

Input:
3 
-1 2 3
1
1 2
Output:
2

Added by:Nguyen Dinh Tu
Date:2006-11-01
Time limit:1s-2s
Source limit:5000B
Languages:All except: ERL JS PERL 6

经典线段树

题意:给定一个静态序列 求[a,b]之间的最大子串和...

每个节点维护sum(区间总和) , max(最大和子串) , Lmax(从左端点开始的最大子串和) , Rmax(从左端点开始的最大子串和)四个域

      tree[ v ].sum := tree[ Ls ].sum + tree[ Rs ].sum ;
      tree[ v ].Lmax := max( tree[ Ls ].Lmax , tree[ Ls ].sum + tree[ Rs ].Lmax );
      tree[ v ].Rmax := max( tree[ Rs ].Rmax , tree[ Rs ].sum + tree[ Ls ].Rmax );
      tree[ v ].max := max( max( tree[ Ls ].max , tree[ Rs ].max ) , tree[ Ls ].Rmax + tree[ Rs ].Lmax );

 

 

 

https://www.spoj.pl/problems/GSS3/ 

SPOJ Problem Set (classical)

1716. Can you answer these queries III

Problem code: GSS3

 

You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations:
modify the i-th element in the sequence or for given x y print max{Ai + Ai+1 + .. + Aj | x<=i<=j<=y }.

Input

The first line of input contains an integer N. The following line contains N integers, representing the sequence A1..AN.
The third line contains an integer M. The next M lines contain the operations in following form:
0 x y: modify Ax into y (|y|<=10000).
1 x y: print max{Ai + Ai+1 + .. + Aj | x<=i<=j<=y }.

Output

For each query, print an integer as the problem required.

Example

Input:
4
1 2 3 4
4
1 1 3
0 3 -3
1 2 4
1 3 3

Output:
6
4
-3

Added by:Jin Bin
Date:2007-08-03
Time limit:1s
Source limit:5000B
Languages:All except: C99 strict ERL JS PERL 6
Resource:

own problem

 

 

 

 

 

 

 

 


 

只比GSS1多一个改值操作 其它地方一样...

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值