HardRating 2282
2659. Make Array Empty
arraybinary-searchgreedybinary-indexed-treesegment-treesortingordered-set
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Initialize BIT with all positions marked as present 2. Sort elements by value, recording original indices 3. Set prev = 0 (starting position) 4. For each element in sorted order (smallest to largest): a. cur = original index of current element b. If cur >= prev: operations += count of remaining elements in [prev, cur] c. Else (wrap around): operations += remaining in [prev, n-1] + remaining in [0, cur] d. Remove cur from BIT e. Set prev = cur 5. Return total operations