CERC 2019 Presentation of solutions December 3, 2019 ABB [ABBA] - - PowerPoint PPT Presentation

cerc 2019
SMART_READER_LITE
LIVE PREVIEW

CERC 2019 Presentation of solutions December 3, 2019 ABB [ABBA] - - PowerPoint PPT Presentation

CERC 2019 Presentation of solutions December 3, 2019 ABB [ABBA] ABB [ABBA] Task: Find the minimum number of letters to be appended to make the string palindromic. ABB [ABBA] Task: Find the minimum number of letters to be appended to


slide-1
SLIDE 1

CERC 2019

Presentation of solutions

December 3, 2019

slide-2
SLIDE 2

ABB [ABBA]

slide-3
SLIDE 3

ABB [ABBA]

◮ Task: Find the minimum number of letters to be appended to make the string palindromic.

slide-4
SLIDE 4

ABB [ABBA]

◮ Task: Find the minimum number of letters to be appended to make the string palindromic. ◮ Observation: We want to find the longest palindrome among all suffixes of the string and append the reversed prefix to the end of the string.

slide-5
SLIDE 5

ABB [ABBA]

◮ Task: Find the minimum number of letters to be appended to make the string palindromic. ◮ Observation: We want to find the longest palindrome among all suffixes of the string and append the reversed prefix to the end of the string. ◮ We can iterate over all suffixes and check whether it is palindromic. ◮ The check could be done by multiple string matching algorithms. ◮ Examples: Hash, Z-function, Suffix Arrays, Manacher, Palindromic Trees, . . .

slide-6
SLIDE 6

ABB [ABBA]

◮ Task: Find the minimum number of letters to be appended to make the string palindromic. ◮ Observation: We want to find the longest palindrome among all suffixes of the string and append the reversed prefix to the end of the string. ◮ We can iterate over all suffixes and check whether it is palindromic. ◮ The check could be done by multiple string matching algorithms. ◮ Examples: Hash, Z-function, Suffix Arrays, Manacher, Palindromic Trees, . . . ◮ Complexity depends on chosen algorithm: O(N) is achievable.

slide-7
SLIDE 7

Zeldain Garden [Linkin Park]

slide-8
SLIDE 8

Zeldain Garden [Linkin Park]

◮ Task: Find the sum of divisor functions on a range.

slide-9
SLIDE 9

Zeldain Garden [Linkin Park]

◮ Task: Find the sum of divisor functions on a range. ◮ Observation: The task can be splitted into two same tasks: Range(left,right) is equal to Range(1,right)-Range(1,left-1)

slide-10
SLIDE 10

Zeldain Garden [Linkin Park]

◮ Task: Find the sum of divisor functions on a range. ◮ Observation: The task can be splitted into two same tasks: Range(left,right) is equal to Range(1,right)-Range(1,left-1) ◮ Let Q be equal to ⌊N⌋ ◮ All numbers ”lesser” than sqrt: Q

i=1⌊ N i ⌋

◮ All numbers ”greater” than sqrt: Q

i=1⌊ N i ⌋

slide-11
SLIDE 11

Zeldain Garden [Linkin Park]

◮ Task: Find the sum of divisor functions on a range. ◮ Observation: The task can be splitted into two same tasks: Range(left,right) is equal to Range(1,right)-Range(1,left-1) ◮ Let Q be equal to ⌊N⌋ ◮ All numbers ”lesser” than sqrt: Q

i=1⌊ N i ⌋

◮ All numbers ”greater” than sqrt: Q

i=1⌊ N i ⌋

◮ Almost there, where is the mistake?

slide-12
SLIDE 12

Zeldain Garden [Linkin Park]

◮ Task: Find the sum of divisor functions on a range. ◮ Observation: The task can be splitted into two same tasks: Range(left,right) is equal to Range(1,right)-Range(1,left-1) ◮ Let Q be equal to ⌊N⌋ ◮ All numbers ”lesser” than sqrt: Q

i=1⌊ N i ⌋

◮ All numbers ”greater” than sqrt: Q

i=1⌊ N i ⌋

◮ Almost there, where is the mistake? ◮ We included all pairs lesser/equal to Q twice.

slide-13
SLIDE 13

Zeldain Garden [Linkin Park]

◮ Task: Find the sum of divisor functions on a range. ◮ Observation: The task can be splitted into two same tasks: Range(left,right) is equal to Range(1,right)-Range(1,left-1) ◮ Let Q be equal to ⌊N⌋ ◮ All numbers ”lesser” than sqrt: Q

i=1⌊ N i ⌋

◮ All numbers ”greater” than sqrt: Q

i=1⌊ N i ⌋

◮ Almost there, where is the mistake? ◮ We included all pairs lesser/equal to Q twice. ◮ (2 · Q

i=1⌊ N i ⌋)-Q2

slide-14
SLIDE 14

Zeldain Garden [Linkin Park]

◮ Task: Find the sum of divisor functions on a range. ◮ Observation: The task can be splitted into two same tasks: Range(left,right) is equal to Range(1,right)-Range(1,left-1) ◮ Let Q be equal to ⌊N⌋ ◮ All numbers ”lesser” than sqrt: Q

i=1⌊ N i ⌋

◮ All numbers ”greater” than sqrt: Q

i=1⌊ N i ⌋

◮ Almost there, where is the mistake? ◮ We included all pairs lesser/equal to Q twice. ◮ (2 · Q

i=1⌊ N i ⌋)-Q2

◮ Complexity is O( √ N)

slide-15
SLIDE 15

The Bugs [The Beatles]

slide-16
SLIDE 16

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence.

slide-17
SLIDE 17

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33).

slide-18
SLIDE 18

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33). ◮ BUT: There are only 13 of patterns after normalisation: 111,112,121,122,123,132,211,212,213,221,231,312,321

slide-19
SLIDE 19

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33). ◮ BUT: There are only 13 of patterns after normalisation: 111,112,121,122,123,132,211,212,213,221,231,312,321 ◮ BUT: There are nonly 5 patterns which are not isomorphic after reverse and ∞-value: 111,112,121,123,132

slide-20
SLIDE 20

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33). ◮ BUT: There are only 13 of patterns after normalisation: 111,112,121,122,123,132,211,212,213,221,231,312,321 ◮ BUT: There are nonly 5 patterns which are not isomorphic after reverse and ∞-value: 111,112,121,123,132 ◮ 111: Simple frequence array.

slide-21
SLIDE 21

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33). ◮ BUT: There are only 13 of patterns after normalisation: 111,112,121,122,123,132,211,212,213,221,231,312,321 ◮ BUT: There are nonly 5 patterns which are not isomorphic after reverse and ∞-value: 111,112,121,123,132 ◮ 111: Simple frequence array. ◮ 123: Fix the 2 and check prefix minimum and suffix maximum.

slide-22
SLIDE 22

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33). ◮ BUT: There are only 13 of patterns after normalisation: 111,112,121,122,123,132,211,212,213,221,231,312,321 ◮ BUT: There are nonly 5 patterns which are not isomorphic after reverse and ∞-value: 111,112,121,123,132 ◮ 111: Simple frequence array. ◮ 123: Fix the 2 and check prefix minimum and suffix maximum. ◮ 112: Combination of frequence array and suffix maximum.

slide-23
SLIDE 23

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33). ◮ BUT: There are only 13 of patterns after normalisation: 111,112,121,122,123,132,211,212,213,221,231,312,321 ◮ BUT: There are nonly 5 patterns which are not isomorphic after reverse and ∞-value: 111,112,121,123,132 ◮ 111: Simple frequence array. ◮ 123: Fix the 2 and check prefix minimum and suffix maximum. ◮ 112: Combination of frequence array and suffix maximum. ◮ 121: Check maximum between first and last occurence of each value.

slide-24
SLIDE 24

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33). ◮ BUT: There are only 13 of patterns after normalisation: 111,112,121,122,123,132,211,212,213,221,231,312,321 ◮ BUT: There are nonly 5 patterns which are not isomorphic after reverse and ∞-value: 111,112,121,123,132 ◮ 111: Simple frequence array. ◮ 123: Fix the 2 and check prefix minimum and suffix maximum. ◮ 112: Combination of frequence array and suffix maximum. ◮ 121: Check maximum between first and last occurence of each value. ◮ 132: Fix the 3 and do combination of prefix minimum and biggest lesser value in suffix.

slide-25
SLIDE 25

The Bugs [The Beatles]

◮ Task: Find the number of normalised 123 patterns in sequence. ◮ There are 27 patterns which are not normalised (33). ◮ BUT: There are only 13 of patterns after normalisation: 111,112,121,122,123,132,211,212,213,221,231,312,321 ◮ BUT: There are nonly 5 patterns which are not isomorphic after reverse and ∞-value: 111,112,121,123,132 ◮ 111: Simple frequence array. ◮ 123: Fix the 2 and check prefix minimum and suffix maximum. ◮ 112: Combination of frequence array and suffix maximum. ◮ 121: Check maximum between first and last occurence of each value. ◮ 132: Fix the 3 and do combination of prefix minimum and biggest lesser value in suffix. ◮ Complexity is O(N log N)

slide-26
SLIDE 26

Be Geeks [Bee Gees]

slide-27
SLIDE 27

Be Geeks [Bee Gees]

◮ Task: Sum the products of GCD and max for each subarray.

slide-28
SLIDE 28

Be Geeks [Bee Gees]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum.

slide-29
SLIDE 29

Be Geeks [Bee Gees]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum. ◮ Now we have to find all blocks with the same GCD to left and to right: Then we can count the answer from all combinations.

slide-30
SLIDE 30

Be Geeks [Bee Gees]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum. ◮ Now we have to find all blocks with the same GCD to left and to right: Then we can count the answer from all combinations. ◮ Observation: There are at most O(log MAX) such blocks.

slide-31
SLIDE 31

Be Geeks [Bee Gees]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum. ◮ Now we have to find all blocks with the same GCD to left and to right: Then we can count the answer from all combinations. ◮ Observation: There are at most O(log MAX) such blocks. ◮ There are multiple methods to find the blocks – for example:

◮ Combination of previously stated Data Structure and Binary search. ◮ Factorisation and searching for next.

slide-32
SLIDE 32

Be Geeks [Bee Gees]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum. ◮ Now we have to find all blocks with the same GCD to left and to right: Then we can count the answer from all combinations. ◮ Observation: There are at most O(log MAX) such blocks. ◮ There are multiple methods to find the blocks – for example:

◮ Combination of previously stated Data Structure and Binary search. ◮ Factorisation and searching for next.

◮ Complexity is O(N log3 MAX)

slide-33
SLIDE 33

K==S [Kiss]

slide-34
SLIDE 34

K==S [Kiss]

◮ Task: Find the number of strings of length N which do not contain any of given strings as a substring.

slide-35
SLIDE 35

K==S [Kiss]

◮ Observation: It can also be solved by computing the number

  • f strings containing any of them as a substring. Then the

solution is 26N − ANS.

slide-36
SLIDE 36

K==S [Kiss]

◮ Observation: It can also be solved by computing the number

  • f strings containing any of them as a substring. Then the

solution is 26N − ANS. ◮ We have to find out the way to build all such strings.

slide-37
SLIDE 37

K==S [Kiss]

◮ Observation: It can also be solved by computing the number

  • f strings containing any of them as a substring. Then the

solution is 26N − ANS. ◮ We have to find out the way to build all such strings. ◮ This can be done by constructing the Aho-Corasick automaton. ◮ It wasn’t needed to construct this automaton efficiently as there are at most Q = 100 characters involved (there will be ≈ Q states in the automaton).

slide-38
SLIDE 38

K==S [Kiss]

◮ Then we figure out approach to solve the problem, though for much lower limit of N. ◮ We will use Dynamic Programming where the state configuration is combination of length of the string and the state of the automation that we’re currently in. ◮ Time complexity of this approach is O(N · Q). ◮ Too slow to fit the constraints of the problem · · · .

slide-39
SLIDE 39

K==S [Kiss]

◮ Finally we need to optimize DP approach to fit in the time limit. ◮ We will do so by using Matrix Exponentiation. ◮ Similarly to the DP approach we will create the transition matrix and use its N-th power to compute the answer. ◮ Time complexity of this approach is O(L3 log N).

slide-40
SLIDE 40

Ponk Warshall [Pink Floyd]

slide-41
SLIDE 41

Ponk Warshall [Pink Floyd]

◮ Task: Compose a reordering of a string on four letters from fewest possible swaps.

slide-42
SLIDE 42

Ponk Warshall [Pink Floyd]

◮ Task: Compose a reordering of a string on four letters from fewest possible swaps. ◮ Reformulation:

◮ Directed graph on 4 vertices, edges with multiplicities.

A C G T nac nca

◮ Decompose the graph into maximum possible number of cycles.

slide-43
SLIDE 43

Ponk Warshall [Pink Floyd]

◮ Task: Compose a reordering of a string on four letters from fewest possible swaps. ◮ Reformulation:

◮ Directed graph on 4 vertices, edges with multiplicities.

A C G T nac nca

◮ Decompose the graph into maximum possible number of cycles.

◮ Greedily start with 2-cycles, then 3-cycles and cover the rest with 4-cycles. ◮ Complexity is O(N).

slide-44
SLIDE 44

Ponk Warshall 2-cycles

◮ Assume the 2-cycle is covered differently.

A C G T A C G T

◮ Then we can change the covering without decreasing the number of cycles.

slide-45
SLIDE 45

Ponk Warshall 3-cycles

◮ After covering 2-cycles, only one case remains

A C G T nac ncg ngt nta nag nct

(up to isomorphism) ◮ Only two directed 3-cycles (with one shared edge).

A C G T

slide-46
SLIDE 46

Light Emitting Hindenburg [Led Zeppelin]

slide-47
SLIDE 47

Light Emitting Hindenburg [Led Zeppelin]

◮ Task: Find the maximum binary AND which could be

  • btained as sequence of K numbers.
slide-48
SLIDE 48

Light Emitting Hindenburg [Led Zeppelin]

◮ Task: Find the maximum binary AND which could be

  • btained as sequence of K numbers.

◮ Observation: We can never get bigger answer from lesser bits than we would get if we achieve to persist a higher bit.

slide-49
SLIDE 49

Light Emitting Hindenburg [Led Zeppelin]

◮ Task: Find the maximum binary AND which could be

  • btained as sequence of K numbers.

◮ Observation: We can never get bigger answer from lesser bits than we would get if we achieve to persist a higher bit. ◮ This means we can greedily iterate from most significant bits and check, whether there are at least K of them in numbers we have: ◮ In case of YES: We reduce the set of numbers to those with this bit on and OR 2i with the answer. ◮ In case of NO: We simply go to another bit.

slide-50
SLIDE 50

Light Emitting Hindenburg [Led Zeppelin]

◮ Task: Find the maximum binary AND which could be

  • btained as sequence of K numbers.

◮ Observation: We can never get bigger answer from lesser bits than we would get if we achieve to persist a higher bit. ◮ This means we can greedily iterate from most significant bits and check, whether there are at least K of them in numbers we have: ◮ In case of YES: We reduce the set of numbers to those with this bit on and OR 2i with the answer. ◮ In case of NO: We simply go to another bit. ◮ Complexity is O(N log MAX)

slide-51
SLIDE 51

Crimson Sexy Jalape˜ nos [Red Hot Chilli Peppers]

slide-52
SLIDE 52

Crimson Sexy Jalape˜ nos [Red Hot Chilli Peppers]

◮ Task: Win a game of chockolate-eating against ”AI”.

slide-53
SLIDE 53

Crimson Sexy Jalape˜ nos [Red Hot Chilli Peppers]

◮ Task: Win a game of chockolate-eating against ”AI”. ◮ Observation: We can divide the game into four ”independent” games – as for each side – played at once.

slide-54
SLIDE 54

Crimson Sexy Jalape˜ nos [Red Hot Chilli Peppers]

◮ Task: Win a game of chockolate-eating against ”AI”. ◮ Observation: We can divide the game into four ”independent” games – as for each side – played at once. ◮ It can be transformed into a NIM game with four piles (while subtracting any number from a pile).

slide-55
SLIDE 55

Crimson Sexy Jalape˜ nos [Red Hot Chilli Peppers]

◮ Task: Win a game of chockolate-eating against ”AI”. ◮ Observation: We can divide the game into four ”independent” games – as for each side – played at once. ◮ It can be transformed into a NIM game with four piles (while subtracting any number from a pile). ◮ The winability of game can be decided by XORing the sizes of state while. ◮ If the XOR is equal to 0 the state is lost.

slide-56
SLIDE 56

Crimson Sexy Jalape˜ nos [Red Hot Chilli Peppers]

◮ Task: Win a game of chockolate-eating against ”AI”. ◮ Observation: We can divide the game into four ”independent” games – as for each side – played at once. ◮ It can be transformed into a NIM game with four piles (while subtracting any number from a pile). ◮ The winability of game can be decided by XORing the sizes of state while. ◮ If the XOR is equal to 0 the state is lost. ◮ Similary we can decide the next move: ◮ We have to take a number from a pile, such that after taking the number, the XOR will be 0. ◮ NOTE: It can be proven that it is always possible to find such move.

slide-57
SLIDE 57

Crimson Sexy Jalape˜ nos [Red Hot Chilli Peppers]

◮ Task: Win a game of chockolate-eating against ”AI”. ◮ Observation: We can divide the game into four ”independent” games – as for each side – played at once. ◮ It can be transformed into a NIM game with four piles (while subtracting any number from a pile). ◮ The winability of game can be decided by XORing the sizes of state while. ◮ If the XOR is equal to 0 the state is lost. ◮ Similary we can decide the next move: ◮ We have to take a number from a pile, such that after taking the number, the XOR will be 0. ◮ NOTE: It can be proven that it is always possible to find such move. ◮ Complexity is O(N) (as the game could consist of O(N) moves.

slide-58
SLIDE 58

Bob in Wonderlands [Alice in Chains]

slide-59
SLIDE 59

Bob in Wonderlands [Alice in Chains]

◮ Task: Minimal number of edge reconnections to make a tree become a path.

slide-60
SLIDE 60

Bob in Wonderlands [Alice in Chains]

◮ Task: Minimal number of edge reconnections to make a tree become a path. ◮ Lower bound: We have to get rid of all degrees larger than 2.

slide-61
SLIDE 61

Bob in Wonderlands [Alice in Chains]

◮ Task: Minimal number of edge reconnections to make a tree become a path. ◮ Lower bound: We have to get rid of all degrees larger than 2. ◮ Procedure: Disconnect every such an edge and connect it to some leaf (it always exists).

slide-62
SLIDE 62

Bob in Wonderlands [Alice in Chains]

◮ Task: Minimal number of edge reconnections to make a tree become a path. ◮ Lower bound: We have to get rid of all degrees larger than 2. ◮ Procedure: Disconnect every such an edge and connect it to some leaf (it always exists). ◮ Obviously we don’t have to simulate the procedure!

slide-63
SLIDE 63

Bob in Wonderlands [Alice in Chains]

◮ Task: Minimal number of edge reconnections to make a tree become a path. ◮ Lower bound: We have to get rid of all degrees larger than 2. ◮ Procedure: Disconnect every such an edge and connect it to some leaf (it always exists). ◮ Obviously we don’t have to simulate the procedure! ◮ Simply count the number of reconnections (sum of all degrees higher than 2 minus 2).

slide-64
SLIDE 64

Bob in Wonderlands [Alice in Chains]

◮ Task: Minimal number of edge reconnections to make a tree become a path. ◮ Lower bound: We have to get rid of all degrees larger than 2. ◮ Procedure: Disconnect every such an edge and connect it to some leaf (it always exists). ◮ Obviously we don’t have to simulate the procedure! ◮ Simply count the number of reconnections (sum of all degrees higher than 2 minus 2). ◮ Complexity is O(N)

slide-65
SLIDE 65

Saba1000kg [Sabaton]

slide-66
SLIDE 66

Saba1000kg [Sabaton]

◮ Task: For each induced subgraph count the number of components.

slide-67
SLIDE 67

Saba1000kg [Sabaton]

◮ Task: For each induced subgraph count the number of components. ◮ Observation (for N = M = Q = 105): The total number of edges among all subgraphs is at most O(N √ N)

slide-68
SLIDE 68

Saba1000kg [Sabaton]

◮ Task: For each induced subgraph count the number of components. ◮ Observation (for N = M = Q = 105): The total number of edges among all subgraphs is at most O(N √ N) ◮ Proof: Worst case if clique in each query. Note that we can’t make clique with more than O(N) edges (by taking M as √ N). There are at most √ N such queries.

slide-69
SLIDE 69

Saba1000kg [Sabaton]

◮ Task: For each induced subgraph count the number of components. ◮ Observation (for N = M = Q = 105): The total number of edges among all subgraphs is at most O(N √ N) ◮ Proof: Worst case if clique in each query. Note that we can’t make clique with more than O(N) edges (by taking M as √ N). There are at most √ N such queries. ◮ To build the graph we have to consider two cases:

  • 1. For each query of size M greater than

√ N, go through all edges and check, whether they are in the given set. # of checked edges:

N M N < N √ N N < N

√ N

  • 2. For each query of size M lesser/equal than

√ N, check for all pairs of vertices, whether there is an edge connecting them. # of checked edges:

N M M2 = NM ≤ N

√ N

slide-70
SLIDE 70

Saba1000kg [Sabaton]

◮ Task: For each induced subgraph count the number of components. ◮ Observation (for N = M = Q = 105): The total number of edges among all subgraphs is at most O(N √ N) ◮ Proof: Worst case if clique in each query. Note that we can’t make clique with more than O(N) edges (by taking M as √ N). There are at most √ N such queries. ◮ To build the graph we have to consider two cases:

  • 1. For each query of size M greater than

√ N, go through all edges and check, whether they are in the given set. # of checked edges:

N M N < N √ N N < N

√ N

  • 2. For each query of size M lesser/equal than

√ N, check for all pairs of vertices, whether there is an edge connecting them. # of checked edges:

N M M2 = NM ≤ N

√ N

◮ The checking step can be done (for example) with O(log N)

  • verhead if we use some standard set implementation.
slide-71
SLIDE 71

Saba1000kg [Sabaton]

◮ Whenever the graph is built, the number of components is easily obtained in linear time by a couple of DFS calls.

slide-72
SLIDE 72

Saba1000kg [Sabaton]

◮ Whenever the graph is built, the number of components is easily obtained in linear time by a couple of DFS calls. ◮ Complexity is O(N √ N log N)

slide-73
SLIDE 73

Deep800080 [Deep Purple]

slide-74
SLIDE 74

Deep800080 [Deep Purple]

◮ Task: Sum the products of GCD and max for each subarray.

slide-75
SLIDE 75

Deep800080 [Deep Purple]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum.

slide-76
SLIDE 76

Deep800080 [Deep Purple]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum. ◮ Now we have to find all blocks with the same GCD to left and to right: Then we can count the answer from all combinations.

slide-77
SLIDE 77

Deep800080 [Deep Purple]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum. ◮ Now we have to find all blocks with the same GCD to left and to right: Then we can count the answer from all combinations. ◮ Observation: There are at most O(log MAX) such blocks.

slide-78
SLIDE 78

Deep800080 [Deep Purple]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum. ◮ Now we have to find all blocks with the same GCD to left and to right: Then we can count the answer from all combinations. ◮ Observation: There are at most O(log MAX) such blocks. ◮ There are multiple methods to find the blocks – for example:

◮ Combination of previously stated Data Structure and Binary search. ◮ Factorisation and searching for next.

slide-79
SLIDE 79

Deep800080 [Deep Purple]

◮ Task: Sum the products of GCD and max for each subarray. ◮ Lets Divide and Conquer the array by maximum. ◮ This could be efficiently done by some data structure: For example Segment Tree or Sparse Table. ◮ Now we can proccess all subarrays and multiply them by the maximum. ◮ Now we have to find all blocks with the same GCD to left and to right: Then we can count the answer from all combinations. ◮ Observation: There are at most O(log MAX) such blocks. ◮ There are multiple methods to find the blocks – for example:

◮ Combination of previously stated Data Structure and Binary search. ◮ Factorisation and searching for next.

◮ Complexity is O(N log3 MAX)

slide-80
SLIDE 80

Screamers in the Storm [by Emerald Sun]

slide-81
SLIDE 81

Screamers in the Storm [by Emerald Sun]

slide-82
SLIDE 82

Thank you for your attention!