## Dynamic Summation

Given a tree of N nodes, where each node is uniquely numbered in between [1, N]. Each node also has a value which is initially 0. You need to perform following two operations in the tree. Update Operation Report Operation Update Operation U r t a b Adds ab + (a+1)b + (b+1)a to all nodes in the subtree rooted at t, considering that tree is rooted at r (see explanation for more details). Report Operation R r t m Output the sum of all nodes in the subtree rooted at t, considering th

View Solution →## Jaggu Playing with Balloons

Jaggu is a little kid and he likes playing with water balloons. He took 1 million ( 106 ) empty buckets and he filled the bucket with water balloons under the instruction of his sister Ishika. His sister gives him two types of commands: R pos1 pos2 which implies that jaggu needs to tell her what is the total number of water balloons in the bucket from pos1 to pos2 (both included). U pos M plus which implies that he has to work like the function Update(pos,M,plus) void Update(int pos

View Solution →## Taxicab Driver's Problem

Burger Town is a city that consists of special junctions and pathways. There is exactly one shortest path between each pair of junctions. Junction is located at and the distance between two junctions is defined by the Taxicab geometry. Tim has recently afforded a taxicab to work as a taxicab driver. His vehicle was very cheap, but has a very big flaw. It can only drive units horizontally and units vertically before refueling. If a customer wants to be brought from a junction to ano

View Solution →## Find Maximum Index Product

You are given a N list of numbers . For each element at position (), we define and as: = closest index j such that j < i and . If no such j exists then = 0. = closest index k such that k > i and . If no such k exists then = 0. We define = * . You need to find out the maximum among all i. Input Format The first line contains an integer , the number of integers. The next line contains the integers describing the list a[1..N]. Constraints 1 <= N <= 10^5 1 <= ai <

View Solution →## Divisibility

Two positive integers P and S are given. is decimal representation of integer . Lets define . For example, if : For each query you will be given two integers and that define a substring equal to . Your task is to calculate divisibility of given substring. Divisibility of given substring is equal to number of pairs such that: and is divisible by , assuming that is divisible by any other integer. Timelimits Timelimits for this challenge is given here Input Format Fi

View Solution →