Sei sulla pagina 1di 6

You are given a row of N Bijlibulbs, numbered from 1 to N.

You know about each Bijlibulbs


whether it's turned on or off. You can change the state of Bijlibulbs i if Bijlibulb i+1 is turned
on and Bijlibulbs i+2, i+3, … N are turned off. This rule doesn't apply to lightbulb N, which
can be switched on or off at will.

Compute the minimum number of switches you need to make in order to turn off all the
Bijlibulbs.

Input Format

The input contains a single string of values from the set {0,1}. N is equal to the length of the
string, and each Bijlibulb is represented by a char. A Bijlibulb that is switched off is
represented by a 0, and one that is switched on by a 1.

Constraints

1 ≤ N ≤ 50.

Output Format

The output should contain a single number representing the minimum number of switches
needed.

Sample Input
1011
Sample Output
13
You are given a number n, denoting number of vertical fences of width 1metre. In the
next row, you will be given height of each fence in metres. Now you want to paint these
fences in minimum number of horizontal strokes or vertical strokes possible. During one
stroke, the brush should touch fence at all times. You can paint the same area multiple
times.

Input Format

First Line : n , no of fences Second Line : Height of each fence

Constraints

n <= 5000 Each array element <= 10^9

Output Format

Minimum strokes possible

Sample Input
5
2 2 1 2 1
Sample Output
3
Explanation

1st stroke : Horizontally along all the planks 2nd stroke : horizontally on 1 and 2 3rd
stroke : horizontally/vertically on 4

{...} Code Editor

Provide Custom Input


Compile and Test Submit Code
u have an array of n elements a1 , a2 …. an, initially all set to 0. You want to perform two
types of queries on this array :

1 j x: Update the value of aj to x i.e set aj = x

2 y : Find the spectral value of subarray a1 , a2 …. ay, which is defined as product of (c[p]+1)
(c[p]+1)
for all p.

Here c[p] is the number of times p occurs in the subarray [a1 , a2 …. ay], where p takes the
value of each of the distinct elements present in the subarray.

Input Format

First line of input contains n and q, the number of queries to be performed. Next q lines
consists of queries in the aforementioned format.

Constraints

1 ≤ n ≤ 10^5

1 ≤ q ≤ 10^5

1 ≤ x, y ≤ n

Output Format

For each query of type 2, output the spectral value modulo 109 + 7, in a new line.

Sample Input
8 5
1 3 5
2 2
2 6
1 1 4
2 8
Sample Output
27
186624
13176688
Explanation

After first query the array becomes [0,0,5,0,0,0,0,0].

In the second query, subarray [0,0] is considered. Since 0 occurs twice, the spectral
value becomes (2+1)(2+1)=27

In the third query, in subarray [0,0,5,0,0,0], the spectral value becomes (5+1) (5+1)*(1+1)
(1+1)
= 186624, since 0 appears five times and 5 appears once in the subarray.
In the fourth query, the array becomes [4,0,5,0,0,0,0,0].

Similarly, in the fifth query, in subarray [4,0,5,0,0,0,0,0], the spectral value becomes
(6+1)(6+1)*(1+1)(1+1)*(1+1)(1+1) = 13176688.
Thor made an escape plan from Sakaar Planet with Bruce Banner. He told Bruce that they
will find the Quinjet and fly their way along to Asgard easily. But Banner told Thor that in
order to fly Quinjet Thor has to solve a puzzle. Given a number A, Thor is supposed to find
the count of numbers that are when added to A or Xored(Bitwise Xor) with A gives the same
value. Thor is supposed to print the total count of such numbers.

Input Format

A single integer, A

Constraints

0 ≤ A ≤ 10^15

Output Format

Print the total number of integers satisfying the criteria.

Sample Input
5
Sample Output
2
Explanation

5+0 = 5 and 5^0=5


5+2 = 7 and 5^2=7
So there are two such numbers which either added with A or Xored with A gives the
same value.
A painter is painting a wall. It is in the form of a matrix of cells, with a rows and b columns.
He moves the brush as follows: the 1st row, the 2nd row, and so on upto the ath row, then across
the a-1th row, a-2th row upto the 1st row, then back to the 2nd row, and so on. The brush always
moves across the row from left to right, i.e. from the 1st cell to the bth. The painter paints
exactly n cells and then stops.

You notice that in this method the cells get uneven coatings. You set out to prove this.

Input Format

The first line contains the number of test cases.

The next T lines contain five integers: a, b, n, x and y.

Constraints

1 ≤ T ≤ 10

1 ≤ a, b ≤ 100

1 ≤ n ≤ 10^18

1 ≤ x ≤ a

1 ≤ y ≤ b

Output Format

For each test case print three integers: the maximum coatings on a cell, the minimum coatings
on a cell and coatings on the cell of the xth row and yth column.

Sample Input
2
3 2 15 2 2
4 1 8 3 1
Sample Output
4 2 3
3 1 2

Potrebbero piacerti anche