Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Coding questions that I challenging.

NotificationsYou must be signed in to change notification settings

adityabraj/coding-problems

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

Coding questions that I challenging.

Minimum addition

You are given an array A[] of N positive numbers. You are also given Q queries. Each query contains two integers l,r(l<=r) . For each query, determine the sum of all values that must be added to each number in range l to r such that bitwise AND of all numbers in the range is greater than 0.

You are required to minimize the total value that must be added. The value you must add to numbers is not necessarily equal for all numbers.

Note: Each query is independent of each other, that is, for each query, you must treat the range over the initial input array.

Input format

The first line contains an integer N denoting the number of array elements.The next line denotes N array elements.The next line contains a number Q denoting the number of queries.Next Q lines contain two integers l and r.

Output formatFor each query, print the minimum sum of values to be added in a new line.

Constraints1 <= N <= 10^51 <= A[i] <= 10^91 <= Q <= 10^51 <= l <= r <= N

SAMPLE INPUT
5
4 3 2 4 1
41 4
2 34 44 5

SAMPLE OUTPUT3001

Explanation:For the first query we can add 1 to the 1st, 3rd and, 4th numbers.For the second and third query, we don't need to add as the Bitwise AND is already > 0.For the last query, we can add 1 to 4th number.


[8]ページ先頭

©2009-2025 Movatter.jp