PROBLEM-SET (01-Oct-2011) : Problem A: Consistent Strings
PROBLEM-SET (01-Oct-2011) : Problem A: Consistent Strings
Problem G : Pyramids
You are given an array A[0..N-1].The array element are used to form a pyramid. Your given array A will be the base of pyramid. Each non-base element is sum of immediate lower and lower-right elements. example: say A = {1,2,3,4} . B[0][i] = A[i] and B[i][j] = B[i-1][j] + B[i-1][j+1]. 20 8 12 357 1234 The summation may get very big so use Mod 1000000007. Now you will be given Q queries in which we give the index i of array A[0..N-1] and a value x such that A[i] is updated to x. As the value A[i] is updated the layer above it gets updated and so on... resulting in the topmost value in the pyramid getting updated.So your task is to find the updated top-most value for each query. Input: First line is N Second line contains the N elements i.e. A[i] Third line contains number of query Q. following line contains queries of form "i x" where i is index and x is the value such that A[i] = x Output: Updated Value of top-most value in the pyramid for each query. You have to retain the updation of previous query also.The answer may get very big so report Mod 1000000007. ( followed by a '\n' ). Constraints: 2 <= N <= 1000 1 <= Q <= 10000 1 <= A[i] <=100 Mod value M = 1000000007 Sample Case1: Input: 4 1234 2 03 25 Output: 22 28\n Explanation: Initially A = {1,2,3,4} ; top value = 20 set A[0] = 3 --> A = {3,2,3,4} ; top value = 22 set A[2] = 5 --> A = {3,2,5,4} ; top value = 28