title-img


Two Array Problem

In this problem you operate on two arrays of integers. We will call them the and the respectively. Your goal is just to maintain them under the modification operations, such as: 1 : Reverse the subarray of the array, starting at the number, ending at the number, inclusively; 2 : Swap two consecutive fragments of the array, the first is from the number to the , the second is from the number to the ; 3 : Swap the piece that starts at the number and end at the one between th

View Solution →

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 →