CF1290C Prefix Enlightenment
Description
There are $ n $ lamps on a line, numbered from $ 1 $ to $ n $ . Each one has an initial state off ( $ 0 $ ) or on ( $ 1 $ ).
You're given $ k $ subsets $ A_1, \ldots, A_k $ of $ \{1, 2, \dots, n\} $ , such that the intersection of any three subsets is empty. In other words, for all $ 1 \le i_1 < i_2 < i_3 \le k $ , $ A_{i_1} \cap A_{i_2} \cap A_{i_3} = \varnothing $ .
In one operation, you can choose one of these $ k $ subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation.
Let $ m_i $ be the minimum number of operations you have to do in order to make the $ i $ first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between $ i+1 $ and $ n $ ), they can be either off or on.
You have to compute $ m_i $ for all $ 1 \le i \le n $ .
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the first example:
- For $ i = 1 $ , we can just apply one operation on $ A_1 $ , the final states will be $ 1010110 $ ;
- For $ i = 2 $ , we can apply operations on $ A_1 $ and $ A_3 $ , the final states will be $ 1100110 $ ;
- For $ i \ge 3 $ , we can apply operations on $ A_1 $ , $ A_2 $ and $ A_3 $ , the final states will be $ 1111111 $ .
In the second example:
- For $ i \le 6 $ , we can just apply one operation on $ A_2 $ , the final states will be $ 11111101 $ ;
- For $ i \ge 7 $ , we can apply operations on $ A_1, A_3, A_4, A_6 $ , the final states will be $ 11111111 $ .