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

Автор Yagnik_Dhameliya, 2 года назад, По-английски

Epiphany 13.0

A: Gifts

jaineshmachhi

Tutorial
Code

B: Hulk Smash

jaineshmachhi

Tutorial
Code

C: Fight Between Friends

Yagnik_Dhameliya

Tutorial-1
Tutorial-2
Code-1
Code-2

D: SOS Signal

jaineshmachhi

Tutorial
Code

E1: New Year Games-1

rutvik_1234

Hint 1
Hint 2
Tutorial-1
Code-1

Yagnik_Dhameliya

Tutorial-2
Code-2

E2: New Year Games-2

rutvik_1234

Tutorial-1
Code-1

Yagnik_Dhameliya

Tutorial-2
Code-2

F: Money Distribution

Yagnik_Dhameliya

Hint-1
Hint-2
Hint-3
Hint-4
Tutorial
Code-1

Idea: shiven

Code-2
  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

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

Thanks for the fast editorial!! Nice Contest although wated 6 submissions on C because of not taking fast i/o.

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

If you are using HLD in problem F then it is possible to solve it in $$$O(q \log^2n)$$$ time. Construct HLD and segtree on top of tree. For each node, a range query can be done with range addition on a segtree(store $$$ax + b$$$ for each node and apply range addition appropriately). Path queries can be answered by walking on the segtree. Complexity for both is $$$O(log^2n)$$$.

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

    I was thinking the same but didn't get much clarity on whether this would work. If you have a solution then you can share that. It will be useful for others to understand the approach.

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

      Consider a segtree with following operations —

      1) Range add $$$(a,b)$$$
      2) Find range sum of $$$ax + b$$$

      Once you make this segtree just apply it on the tree. HLD will have additional $$$\log n$$$ factor making each operation $$$\log^2 n$$$. A nice implementation of HLD is here — https://mirror.codeforces.com/blog/entry/81317

      Alternatively you can flatten the tree and create fenwick trees of size $$$2*n$$$ to store sum of $$$a$$$ and $$$b$$$ from root to current node. Each query of type 1 can be broken into queries of $$$(a,b)$$$ from root to node and $$$(-a,-b)$$$ from root to LCA. For query of type 2, just iterate over all nodes from node to LCA. Value of current node is $$$sum_a(Enter[node],Exit[node]) \cdot x + sum_b(Enter[node],Exit[node])$$$. Unlike last method, this needs sum of path sums over all queries to be small.

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

i solved e1 and e2 using small to large merging But I will look for dsu also

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

in problem d, i find (x,y) in d but dont know how it works if just making x>=0 or y>=0 gives us optimal answer

Any proof Yagnik_Dhameliya shadow9236

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

Alternate solution for D,

WLOG, assume that $$$a+c \lt b+d$$$. First ship will send signals at every time t for which $$$t$$$ mod $$$c$$$ $$$\equiv$$$ $$$a$$$ mod $$$c$$$ and $$$t \geq a + c$$$. Therefore we need to find smallest $$$x \geq 0$$$ for which $$$(b + d + d \cdot x)$$$ mod $$$c \equiv a$$$ mod $$$c$$$. Let $$$y = gcd(c, d)$$$. $$$d \cdot x$$$ mod $$$c \equiv (a-b-d)$$$ mod $$$c$$$

Therefore, possible values for $$$x$$$ exist only if $$$y | (a-b-d)$$$ mod $$$c$$$, and can be found by,

$$$(d/y) \cdot x$$$ mod $$$(c / y) \equiv ((a-b-d) / y)$$$ mod $$$(c / y)$$$

Since, $$$(d/y)$$$ and $$$(c/y)$$$ are coprime, we can find $$$(d/y)^{-1} mod (c/y)$$$ using Euclidean theorem or Euler's theorem (will need to use Pollard Rho to use that). Then, their signals will occur simultaneously for all values of x for which $$$x$$$ mod $$$(c / y) \equiv ((a-b-d) / y) \cdot ((d/y)^{-1} mod (c/y)) $$$ mod $$$(c / y)$$$

so the answer would be $$$b + d + d*x$$$

  • »
    »
    2 года назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +8 Проголосовать: не нравится

    Great approach thanks for sharing 

    C++ Implementation