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

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

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2019A — Max Plus Size

Video

2019B — All Pairs Segments

Video

2019C — Cards Partition

Video

2019D — Speedbreaker

Video

2019E — Tree Pruning

Video
Разбор задач Codeforces Round 975 (Div. 2)
  • Проголосовать: нравится
  • +45
  • Проголосовать: не нравится

»
2 месяца назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

Update: Now Videos are playing. Thank you Shayan for the video tutorial.

Video tutorials are not playing! It shows this error An error occurred. Please try again later. (Playback ID: dLE5_mB8I9IVhzlN)

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

Why all downvotes? I think these videos are much better than texts.

»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I still don't understand how to solve the problem B-All Pairs.

Please help.

  • »
    »
    2 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    You can check out the explanation by ninjacoder2209 in this video, he has explained it very nicely as well. It might give you some more clearity

    https://www.youtube.com/watch?v=2M5S9QNetg4

  • »
    »
    7 недель назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    We can derive a formula for each of the points in the array a to find out in how many segments they exist. Now for the numbers between each element of a (if any exist) the formula for how many segments they exist in is slightly different.

    Anyhow, once we have the said formula, we can start looping through the array a and in a map store the number of segments the element ai exists in and increment it if any other ai exists the same number of times. For the numbers between ai, we do the same thing.

    Once we have this map of segments and the count of numbers that exist in these segments we can loop through queries, see if they exist and then output the answer accordingly.

    Here's a python code that breaks it down and I have added comments as well that break down the formula derivation.

    t = int(input())
    for i in range(t):
        n, q = list(map(int, input().split(" ")))
        a = list(map(int, input().split(" ")))
        k = list(map(int, input().split(" ")))
    
        ans = {}
    
        l = n
        n -= 1
        for i in range(l-1):
            ans[a[i]] = n-i + i*(n-i+1)
    
            if a[i+1] - a[i] > 1:
                ans[a[i]+1] = n-i + i*(n-i)
        ans[a[i+1]] = n
    
        print(ans)
    
        """
        1 2 3 5 6 7
    
        1 = 5
        2 = 4 + 5                   = 9
        3 = 3 + 4 + 4 or (5-1)      = 11
        # 4 = 3 + 3 or (4-1) + 3 or (4-1) = 9
        5 = 2 + 3 + 3 + 3 = 11
        7 = 1 + 1 + 1 + 1 + 1 =
    
        1 = n
        2 = n-1 + n
        3 = n-2 + 2*(n-1)
        .
        4 = n-2 + 2*(n-2)
        .
        5 = n-3 + 3*(n-2)
        6 = n-4 + 4*(n-3)
        7 = n-5 + 5*(n-4)
        """