title-img


Triplets

There is an integer array d which does not contain more than two elements of the same value. How many distinct ascending triples (d[i],< d[j] < d[k] , i < j < k ) are present? Input format The first line contains an integer, N, denoting the number of elements in the array. This is followed by a single line, containing N space-separated integers. Please note that there are no leading spaces before the first number, and there are no trailing spaces after the last number. Output format:

View Solution →

BST maintenance

Consider a binary search tree T which is initially empty. Also, consider the first N positive integers {1, 2, 3, 4, 5, ....., N} and its permutation P {a1, a2, ..., aN}. If we start adding these numbers to the binary search tree T, starting from a1, continuing with a2, ... (and so on) ..., ending with aN. After every addition we ask you to output the sum of distances between every pair of T's nodes. Input Format The first line of the input consists of the single integer N, the size of

View Solution →

Max Transform

Transforming data into some other data is typical of a programming job. This problem is about a particular kind of transformation which we'll call the max transform. Let be a zero-indexed array of integers. For , let denote the subarray of from index to index , inclusive. Let's define the max transform of as the array obtained by the following procedure: Let be a list, initially empty. For from to : For from to : Let . Append to the end of . Return . The returned array

View Solution →

Box Operations

Alice purchased an array of n wooden boxes that she indexed from 0 to n - 1 . On each box , she writes an integer that we'll refer to as . Alice wants you to perform q operations on the array of boxes. Each operation is in one of the following forms: (Note: For each type of operations, ) 1 l r c: Add to each . Note that can be negative. 2 l r d: Replace each with . 3 l r: Print the minimum value of any . 4 l r: Print the sum of all . Recall that is the maximum integer such tha

View Solution →

Company Retreat

The LRT Company has employees. Each employee has a unique ID number from 1 to n , where the director's ID is number 1. Every employee in the company has exactly one immediate supervisor — except the director, who has no supervisor. The company's employee hierarchy forms a tree of employee IDs that's rooted at employee number (the director). The director decides to have a retreat lasting days. Each day, the employees will be assigned to different groups for team building exercises. Groups

View Solution →