The Great XOR
Given a long integer x, count the number of values of a satisfying the following conditions: a + x > x 0 < a < x where a and x are long integers and ^ is the bitwise XOR operator. You are given q queries, and each query is in the form of a long integer denoting x. For each query, print the total number of values of a satisfying the conditions above on a new line. For example, you are given the value x=5. Condition 2 requires that a<x. The following tests are run: 1^5 = 4 ^ 5 = 7 3
View Solution →Flipping bits
You will be given a list of 32 bit unsigned integers. Flip all the bits (1->0 and 0->1) and return the result as an unsigned integer. Example n=9(10) 9(10)=1001(2). We're working with 32 bits, so: 000000000000000000000000000001001 = 9(10) 111111111111111111111111111110110 = 4294967286(10) Return 4294967286. Function Description Complete the flippingBits function in the editor below. flippingBits has the following parameter(s): int n: an integer Returns int: the unsigned d
View Solution →Yet Another Minimax Problem
You are given n non-negative integers, a0,a1,...,an-1. We define the score for some permutation () of length to be the maximum of api ^ apI+1 for 0 <= i < n-1. Find the permutation with the minimum possible score and print its score. Note: ^ is the exclusive-OR (XOR) operator. Input Format The first line contains single integer, n, denoting the number of integers. The second line contains n space-separated integers, a0,a1,...,an-1, describing the respective integers. Constraints
View Solution →Swaps and Sum
You are given a sequence a1, a2, a3, . . . an. The task is to perform the following queries on it: Type 1. Given two integers l and r( 1 <= l <= r ; r - l +1 is even ) . Reorder the elements of the sequence in such a way (changed part of the sequence is in brackets): That is swap the first two elements of segment [ l , r ] , the second two elements, and so on. Type 2. Given two integers l and r, print the value of sum . Input Format The first line contains two integers n and q.
View Solution →Coolguy and Two Subsequences
Coolguy gives you a simple problem. Given a 1-indexed array, A , containing N elements, what will ans be after this pseudocode is implemented and executed? Print ans % ( 10^9 + 7 ). //f(a, b) is a function that returns the minimum element in interval [a, b] ans = 0 for a -> [1, n] for b -> [a, n] for c -> [b + 1, n] for d -> [c, n] ans = ans + min(f(a, b), f(c, d)) Input Format The first line contains N (the size of array A). The s
View Solution →