2.6 Training Diary

Yesterday, I played a cf, b problem and it took a long time to make a simulation. All the cars just overturned. Through the last few competitions, many problems have been exposed: When I did the questions several times, my overall thinking was not wrong, but it was always because I missed or didn’t take into account all kinds of problems. The small details caused the problem is that ac can't be done. This is something I will pay attention to in the future (however, I haven't figured out how to strengthen this aspect).

In addition, I would also like to talk about my recent experience in doing questions: many questions have a similar question-making process. The first step: come up with its violent approach (a problem that requires O(n) complexity, O(n 2 ) is generally better). Step 2: Look at what operations the inner loop completes, and whether there is any optimization that can be done. Finally, optimize it to O(n) or O(nlogn).
To give a simple example: C. Array Destruction This inner loop needs to complete the operation: find the maximum value and find whether a number is in the set, in order to quickly complete these two operations, we can use set to maintain one Set, so that the above two operations can be completed within O(logn) complexity, and the total complexity is also optimized from O(n 2 ) to O(n).

According to the cf questions I have done recently, there are many such questions. They all think of a violent approach first, and then optimize the operations they complete. This optimization is sometimes done with data structures, sometimes based on algorithms such as greedy, and sometimes based on the logic of the operation itself (for example: an operation actually only modifies one or two adjacent values ​​compared to the previous operation).
There are many such topics: C. Longest Simple Cycle , C. Fence Painting , B. Hills And Valleys , etc.

Guess you like

Origin blog.csdn.net/li_wen_zhuo/article/details/113735924