There's a shop with N N distinct items numbered 1 1, 2 2, .... N N. There's also a…
- User
There's a shop with N N distinct items numbered 1 1, 2 2, .... N N. There's also a boolean array B B of length N N.
You want to buy all N N items once each, in some order. Say this order is P 1 , P 2 , . . . , P N P 1 ,P 2 ,...,P N . When buying item P i P i ,
If B P i
1 B P i
=1 and there exists some j < i j<i such that P j
P i P j
P i , you get two copies of item P i P i , otherwise you get one copy. Informally, you get two copies if you have bought an item with a larger index before, otherwise you get one copy.
If B P i
0 B P i
=0, it's the opposite - if there exists some j < i j<i such that P j < P i P j
Let f ( B ) f(B) denote the minimum total number of items that you can have in the end.
Given an array B B of length N N, find the f f value of all prefixes. Formally, find the N N integers - f ( B [ 1 , 1 ] ) f(B[1,1]), f ( B [ 1 , 2 ] ) f(B[1,2]), f ( B [ 1 , 3 ] ) f(B[1,3]), ..., f ( B [ 1 , N ] ) f(B[1,N]).
Input Format The first line of input will contain a single integer T T, denoting the number of test cases. Each test case consists of multiple lines of input. The first line of each test case contains N N - the number of items The second line contains N N boolean variables - B 1 , B 2 , . . . , B N B 1 ,B 2 ,...,B N . Output Format For each test case, output on a new line, N N integers - f ( B [ 1 , 1 ] ) f(B[1,1]), f ( B [ 1 , 2 ] ) f(B[1,2]), f ( B [ 1 , 3 ] ) f(B[1,3]), ..., f ( B [ 1 , N ] ) f(B[1,N])
solve this using dp dp i will be result for index i
- Assistant