Constructive Problems

C. Helping the Nature

3 available operations: (1). decrease a[0, i] by 1; (2). decrease a[i, n - 1] by 1; (3). increase a[0, n - 1] by 1.

Key observations

  • The last operation must be type 3. In the case of the last operation as type 1 or 2, we can image that we wasted another No OP of type3. So we need to make all a[i] the same before apply some amount of operation 3 in case of a[i] != 0. 
  • To make all a[i] the same, we need to compare adjacent numbers a[i] and a[i + 1] to determine which operation to apply. 
  • We should only apply decrease operations at this point. Why ? Because type 3 operation does not change the relative difference among all a[i], so any type 3 operations applied not in the end can be swapped into the end, without impacting the final result.
  • If a[i] >= a[i + 1], we can only decrease a[0, i] to make a[i] == a[i + 1].
  • If a[i] < a[i + 1], we can only decrease a[i + 1, n - 1] to make a[i] == a[i + 1].
  • Keep track of the prefix value and a running suffix subtraction sum to determine the adjacent numbers' updated values. 

 

 

D - Swap Hats  Generalization: Inversion number. 

 

 

 

B - Reverse and Compare:  Instead of counting all palindromic substrings, which is O(N^2) time, think about pairs that represent the leftmost and rightmost index of a substring, call it (i, j), if A[i] != A[j] then reversing it gives a differnet string.

 

D - Crossing:  if there are K subsets, can you derive an equation between N and K ?  Draw an example of N = 10, observe the pattern in constructing the answer subsets.

 

Lucky Permutation Triple

If n is even, there is no answer, but if n is odd, set a[i] = b[i] = i.  But why is this correct? Prove it!

 

D - Five, Five Everywhere

 

D - Decrease (Contestant ver.): Construction algorithm problem.  

 

B - LRUD Game: Why go backwards? 

 

 

D. Grid-00100   Latin Square Construct the answer grid using the latin square method.                                            
C. Game with Chips   2*n*m is pretty big of an operation number, and you do not need to get the
minimum number of operations!
First move all points to (1, 1), this takes at most n - 1 + m - 1 operations. Then from (1, 1), go zigzag and visit all cells in n * m - 1 operations.
n - 1 + m - 1 + n * m - 1 <= 2 * n * m.
                                           
A. Sorting Railway Cars     Because we can only either insert at head or tail, so we want to find the
max length of consecutive numbers whose positions are in increasing
order. Once such a sequence is found, we can always put the rest numbers
in their right positions using exactly 1 operation per number.
                                           
  Implement two pointers solution https://www.cnblogs.com/lz87/p/15636146.html                                            
C. The Number Of Good Substrings Prefix Sum The length of substring without leading 0s can not exceed 18 because
2^18 > N. So fix a highest bit 1 and append at most 18 bits then check
if we can get a valid case. Do this for each 1 in S.
https://www.cnblogs.com/lz87/p/15813159.html                                            
B. Different Rules                                                  
                                                 
E. Replace the Numbers     Reference: https://codeforces.com/blog/entry/98001#comment-868680                                            
C. Menorah                                                  
D. Sequence and Swaps                                                  
B. Game on Ranges   O(N^2) is fast enough; There is O(N * logN) solution ?                                              
A. Alyona and mex   Given a number N, if we repeat this pattern 0,1,2,......, N - 1,
then for any range of length >= N, 0 to N - 1 appears at least one time.
The answer is upper bounded by the shortest length subarray, call this length K. Repeat 0,1,2,..., K - 1 is the answer.                                            
E - Friendships                                                  
  When counting answer directly seems hard, think about the total count
minus the counts that do not meet given condition!
N^2 total pairs;
For a pair, the only condition that it does not meet required condition is that the concatenation results in a non-increasing sequence.
So for each given sequence S, if non-increasing, add its min/max range to a list.
Then we count how many pairs from the above list that we can get to form non-increasing concatenated sequence. First sort this list on right range, then for each
range, do a binary search on the number of ranges that lie to the left.
Subtract the above count from N^2.
                                           
                                                 
B. Equivalent Strings                                                  
Stamping the Grid
Constructive, 2D Prefix Sum
                                               
D. Cleaning the Phone
Prefix Sum, Binary Search, Two Pointers
                                               
D. Rating Compression                                                  
B. Ugly Pairs     https://www.cnblogs.com/lz87/p/15820588.html                                            
B. Ciel and Flowers Math                                                
C. Vasya and Robot Binary Search, Prefix Sum                                                
A. Graph and String Graph                                                
B. Treasure Hunt Greedy                                                
                                                 
C. Magic Grid Bitwise                                                
B - Triple Shift inversion count                                                
D - At Most 3 (Contestant ver.)
N-ary notation (positional number system)
                                               
B - 石取り大作戦 Math, Modulo                                                
B - Balanced Neighbors     https://www.cnblogs.com/TheBestQAQ/p/15164112.html                                            
G. Even-Odd XOR Bitwise                                                
C - Lights Out on Tree     https://www.cnblogs.com/lnwhl/p/16703468.html                                            
                                               
posted @ 2021-09-25 11:42  Review->Improve  阅读(146)  评论(0)    收藏  举报