Light OJ 1269 — Consecutive Sum

Правка en3, от flash_7, 2015-08-27 18:20:05

Cany anyone give me some hints how can i solve the problem using segment tree?

Problem Link: Consecutive Sum

Problem Description:

Little Jimmy is learning how to add integers. As in decimal the digits are 0 to 9, it makes a bit hard for him to understand the summation of all pair of digits. Since addition of numbers requires the knowledge of adding digits. So, his mother gave him a software that can convert a decimal integer to its binary and a binary to its corresponding decimal. So, Jimmy's idea is to convert the numbers into binaries, and then he adds them and turns the result back to decimal using the software. It's easy to add in binary, since you only need to know how to add (0, 0), (0, 1), (1, 0), (1, 1). Jimmy doesn't have the idea of carry operation, so he thinks that

1 + 1 = 0
1 + 0 = 1
0 + 1 = 1
0 + 0 = 0

Using these operations, he adds the numbers in binary. So, according to his calculations, 3 (011) + 7 (111) = 4 (100)

Now you are given an array of n integers, indexed from 0 to n-1, you have to find two indices i j in the array (0 ≤ i ≤ j < n) such that the summation (according to Jimmy) of all integers between indices i and j in the array, is maximum. And you also have to find two indices, p q in the array (0 ≤ p ≤ q < n) such that the summation (according to Jimmy) of all integers between indices p and q in the array, is minimum. You only have to report the maximum and minimum integers.

Input Input starts with an integer T (≤ 10), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 50000) The next line contains n space separated non-negative integers, denoting the integers of the given array. Each integer fits into a 32 bit signed integer.

Output For each case, print the case number, the maximum and minimum summation that can be made using Jimmy's addition.

Sample Input: ~~~~~ 2 5 6 8 2 4 2 5 3 8 2 6 5 ~~~~~

Output for Sample Input: ~~~~~ Case 1: 14 2 Case 2: 15 1 ~~~~~

Теги segment tree, trie, advanced data structure

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en7 Английский flash_7 2015-08-27 18:29:45 40 Reverted to en4
en6 Английский flash_7 2015-08-27 18:27:06 40
en5 Английский flash_7 2015-08-27 18:24:19 4
en4 Английский flash_7 2015-08-27 18:21:05 4
en3 Английский flash_7 2015-08-27 18:20:05 1101
en2 Английский flash_7 2015-08-27 18:15:17 20
en1 Английский flash_7 2015-08-27 18:11:44 2102 Initial revision (published)