Find the permutation
Consider a permutation, , of integers from to . Let's determine the of to be the minimum absolute difference between any consecutive integers in : Generate a lexicographically sorted list of all permutations of length having a maximal distance between all permutations of the same length. Print the lexicographically permutation. Input Format The first line contains an integer, t (the number of test cases). The t subsequent lines each contain two space-separated integers, (the p
View Solution →Easy Addition
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
View Solution →Network administration
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
View Solution →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
View Solution →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
View Solution →