https://www.spoj.pl/problems/GSS1/
SPOJ Problem Set (classical)1043. Can you answer these queries IProblem 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 IIIProblem 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多一个改值操作 其它地方一样...