You are given a tree with N nodes and each has a value associated with it. You are given Q queries, each of which is either an update or a retrieval operation. Initially all node values are zero. The update query is of the format a1 d1 a2 d2 A B This means you'd have to add ( a1 + z * d1) * ( a2 - z * d2 ) * R^z in all nodes in the path from A to B where is the distance between the node and A. The retrieval query is of the format i j You need to return the sum of the node valu

Time Limits C:5, Cpp:5, C#:6, Java:8, Php:18, Ruby:20, Python:20, Perl:18, Haskell:10, Scala:14, Javascript:20, Pascal:5 Like every IT company, the Uplink Corporation has its own network. But, unlike the rest of the companies around the world, Uplink's network is subject to very specific restrictions: Any pair of servers within the network should be directly connected by at most 1 link. Each link is controlled by some specific network administrator. No server has more than 2 links connec

## The crazy helix

Natural numbers from 1 to N have been placed in an increasing order over some helix ( a circular structure ). When the helix starts rotating, it is easy to find out The position of a given number The number located at a given position. The helix has numbers arranged in the following fashion: [1, 2, 3, ..., N] Due to some malfunction, the helix has started rotating in a weird manner. Right now, every possible contiguous interval can be rotated, and hence, locating a particular number or

## Rooted Tree

You are given a rooted tree with N nodes and the root of the tree, R, is also given. Each node of the tree contains a value, that is initially empty. You have to mantain the tree under two operations: Update Operation Report Operation Update Operation Each Update Operation begins with the character U. Character U is followed by 3 integers T, V and K. For every node which is the descendent of the node T, update it's value by adding V + d*K, where V and K are the parameters of the query and

## 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