Блог пользователя Sammmmmmm

Автор Sammmmmmm, история, 23 месяца назад, По-английски

Given an array of n integers. In 1 operation you can swap 2 adjacent elements a[i] and a[i + 1] if and only if a[i] + a[i + 1] <=

k. Count the number of possible arrays that can be created using a series of operations (possibly none). Two arrays a and b are

considered different if there exists an index i so that a[i] != b[i]

N <= 1e5

K <= 1e9

Ai <= 1e9

Thanks!

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
23 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится +13 Проголосовать: не нравится
correct me if i'm wrong
»
23 месяца назад, скрыть # |
Rev. 5  
Проголосовать: нравится +1 Проголосовать: не нравится

I have this solution:(the indexing for the array is one based):

If too long to read: https://mirror.codeforces.com/blog/entry/129493?#comment-1149165 simplifies it
EDIT: Now that I think about it, there exist a more clever and cleaner way to implement this approach, but I wrote the first thing that came to mind, so if you wanna read it:

Although the part for calculation the permutations is indeed required, even if u use the other clever implementation. So yes that might be helpful

Detailed solution, also talked about details way of implementation
  • »
    »
    23 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    You don't need to have a multiset, have 3 variables: mn, mx, and length, while advancing the new vertex, if the new_mn - new_mx <= k, the length gets incremented.
    otherwise, the answer gets multiplied by (length! / (all those cnt factorials)). which may help the complexity to lose some constant factor

»
23 месяца назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Bro this comment section turned into a place for specialists(everyone who commented was spec)