E869120's blog

By E869120, 6 weeks ago, In English

Hello, everyone!

Japanese Olympiad in Informatics (JOI) Final Stage 2026 (Contest URL) will be held from March 21st to 24th. There are 4 days in the contest. Note that the Final Stage is a kind of IOI selection camp, which is equivalent to Spring Training in 2025 or before.


The contest information is as follows. Details are available in contest page.

  • Number of problems for each contest: 3-4 problems
  • Style: IOI-Style (There may be some partial scores)
  • Problem Statement: Japanese & English
  • There may be some unusual task (e.g. output-only task, communication task) like IOI

The registration page and live scoreboard will be announced 10 minutes before the contest.

We welcome all participants. Good luck and have fun!


UPD1: The first contest will start in 8 hours.
UPD2: Contest Day 1 is started.
UPD3: Contest Day 1 is ended. You can discuss the problems.
UPD4: Contest Day 2 is started.
UPD5: Contest Day 2 is ended. You can discuss the problems.
UPD6: Contest Day 3 is started.
UPD7: Contest Day 3 is ended. You can discuss the problems.
UPD8: Contest Day 4 is started.
UPD9: Contest Day 4 is ended. You can discuss the problems. Thank you for participating in this event.

Tags joi, ioi
  • Vote: I like it
  • +297
  • Vote: I do not like it

»
6 weeks ago, hide # |
 
Vote: I like it +26 Vote: I do not like it

Is there an error in the scoreboard?

»
6 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When/where can the problems be discussed?

  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it +7 Vote: I do not like it

    the problems are usually discussed under this blog itself, after the contest window ends for everyone (roughly 2 hours from now for day 1)

»
6 weeks ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Where can we upsolve the problems ?

»
6 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve multi? I can't get anything better than $$$log_2{N}+2 = 10$$$

  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it +26 Vote: I do not like it

    The goal is calculating MST weight of the complete graph. A natural first idea is to just run Boruvka until only one component remains: in each round, every vertex sends its cheapest edge leaving its current component, and from all those messages everyone can reconstruct one full Boruvka phase and the new contracted graph. But this requires $$$\lceil \log_2 N \rceil + 1$$$ rounds.

    A 7-round solution:

    • Rounds 1 to 4: run Boruvka. In each round, every vertex sends its cheapest edge leaving its current component. From all N messages, everyone can reconstruct the whole Boruvka phase, contract components, and relabel them. After 4 phases, the number of components is at most $$$\lceil N/16 \rceil \le 16$$$.

    • Round 5: now work on the quotient graph of those remaining components. Since there are at most 16 components, there are at most $$$16 \choose 2$$$ $$$=120$$$ component-pairs. Assign one recipient to each pair $$$(a,b)$$$. Every vertex in component $$$a$$$ sends to that recipient its own cheapest edge into component $$$b$$$, so the recipient can take the minimum and recover the exact edge weight between components $$$a$$$ and $$$b$$$. (If $$$N \lt 120$$$, there are at most 8 components so it works; it works in the same way for smaller $$$N$$$)

    • Round 6: each pair-recipient forwards its computed quotient-edge weight to contestant 0. Contestant 0 also carries the total weight already fixed during the first 4 Boruvka phases.
    • Round 7: contestant 0 now knows the full quotient graph on at most 16 nodes, computes its MST, adds the saved Boruvka total, and outputs the final answer.
    • The only bookkeeping detail is the running MST sum. Contestant 0 keeps it across rounds by using its message to recipient 0 as a private state channel, while still sending ordinary Boruvka information to the other recipients.

    I don't have 6-round solution; wonder how to do it (94 points seems possible in similar approach)

»
6 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Does anyone know the intended time complexity for subtask 4 ($$$n \lt = 5000$$$) of day 1 problem 2 (garden)? I have a $$$O(n^2log(n))$$$ solution that TLE's on it.

»
6 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Does anyone want to explain their approach to dangos and gardens?

  • »
    »
    6 weeks ago, hide # ^ |
    Rev. 4  
    Vote: I like it +21 Vote: I do not like it
    Dangos
    Gardens
»
6 weeks ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

How to solve casino and teleporter?

  • »
    »
    6 weeks ago, hide # ^ |
    Rev. 4  
    Vote: I like it +23 Vote: I do not like it
    Casino
  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Do you know how to solve JOI Tour?

    • »
      »
      »
      6 weeks ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I only know how to solve Subtask 1~8, don't know how to solve the whole problem.

      • »
        »
        »
        »
        6 weeks ago, hide # ^ |
        Rev. 3  
        Vote: I like it 0 Vote: I do not like it

        What was your solution(s) for subtasks 1 — 8?

        • »
          »
          »
          »
          »
          6 weeks ago, hide # ^ |
          Rev. 4  
          Vote: I like it +13 Vote: I do not like it

          First consider a brute force for chain: $$$u = 1, 2, \dots, n$$$
          (in this order!) for every path that contains $$$u$$$, for every other nodes $$$v$$$ lie on the path, let $$$c_{a_v} \leftarrow c_{a_v} + 1$$$, then for $$$k = 1, 2, \dots, q$$$, let $$$ans_i \leftarrow c_{b_k - a_u}$$$, and the complexity is $$$O(nm + nQ)$$$, this can pass Subtask 2,6,8.

          We can split into $$$\sqrt{n}$$$ blocks and change the update-query complexity to $$$O(\sqrt{n})-O(\sqrt{n})$$$ and can pass $$$Q = 1$$$.

          For tree, we can use euler order to reduce the problem to chain.

          • »
            »
            »
            »
            »
            »
            6 weeks ago, hide # ^ |
            Rev. 2  
            Vote: I like it 0 Vote: I do not like it

            In the case of a tree structure, is your Euler sequence something like $$$(v_1, +1), (v_2, +1), (v_2, -1), (v_3, +1), (v_3, -1), (v_1, -1)$$$...?

            I ask this because, during the contest and now, I haven't been able to find a way to represent a path with just a single interval. Does each path consist of a combination of two intervals, such as $$$[tin[lca], tin[s]]$$$ and $$$[tin[next(lca)], tin[t]]$$$?

            • »
              »
              »
              »
              »
              »
              »
              6 weeks ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              For the path $$$u,v(in_u \lt in_v)$$$, if $$$u$$$ is not an ancestor of $$$v$$$ and we use our unchanged euler sequence, $$$u \to u'$$$ will have a coefficent of $$$-1$$$ and $$$v \to v'$$$ will be $$$1$$$, then we multiply $$$[out_u,out_{u'}]$$$ by $$$-1$$$ can fix this issue.

              $$$u'$$$ is the second vertex from $$$\text{lca}(u,v)\to u$$$, same for $$$v'$$$. There is still only $$$O(1)$$$ ranges.

      • »
        »
        »
        »
        6 weeks ago, hide # ^ |
         
        Vote: I like it +15 Vote: I do not like it

        for the final subtasks, i believe a well-implemented $$$O(n (mq)^{0.5})$$$ passes (I implemented that for the line case)

    • »
      »
      »
      6 weeks ago, hide # ^ |
      Rev. 2  
      Vote: I like it +41 Vote: I do not like it

      For chain scenario, decompose the chain into blocks of length $$$\sqrt n$$$, for each whole block in a path, it can be paired with elements in $$$O(1)$$$ intervals in this path, and you calculate this for each block separately, in $$$O(nq+m\sqrt n+n\sqrt n)$$$ time. For partial blocks, we need to calculate ways to pair element using one from $$$[l_1,r_1]$$$ and $$$[l_2,r_2]$$$ each, and the length of the intervals are $$$O(\sqrt n)$$$, so you do sweep line and brute force add all elements in $$$[l_2,r_2]$$$ at time $$$l_1$$$ and exclude them at time $$$r_1+1$$$, also in $$$O(m\sqrt n+nq)$$$ time.

      Tree scenario is just chain + euler tour.

  • »
    »
    6 weeks ago, hide # ^ |
    Rev. 2  
    Vote: I like it +10 Vote: I do not like it
    teleporter
    • »
      »
      »
      6 weeks ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Thank you for your solution!

    • »
      »
      »
      6 weeks ago, hide # ^ |
      Rev. 2  
      Vote: I like it +13 Vote: I do not like it

      Thanks for the detailed explanation!

      A few questions
      • »
        »
        »
        »
        6 weeks ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it
        reply
»
6 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is there a different way to solve teleporter than using DP + aliens trick?

»
6 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why https://cms.ioi-jp.org/ Display 502 Bad Gateway?

»
6 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could anyone share their solutions for Day 3?

  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it +19 Vote: I do not like it

    Sorry, I don't really feel like describing Rainfall right now.

    Scarecrow
    Stamps
    • »
      »
      »
      6 weeks ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      How did you get the centroid to pass the time limit? I only managed to get 72 with this approach.

      • »
        »
        »
        »
        6 weeks ago, hide # ^ |
         
        Vote: I like it +4 Vote: I do not like it

        Fenwick trees are pretty fast, also you can optimize to $$$O(N \cdot log(N))$$$ too, its just slightly annoying (use difference arrays instead of fenwick trees, all all updates before all queries, but this doesn't enforce $$$u$$$ and $$$v$$$ different subtrees so subtract out same subtree)

      • »
        »
        »
        »
        6 weeks ago, hide # ^ |
         
        Vote: I like it +13 Vote: I do not like it

        It's quite easy to optimize to $$$O(n\log n)$$$ with prefix sum.

»
6 weeks ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

This is a solution idea for Voltage, could someone verify that it's correct?

EDIT: Seems to be correct, I just got AC with this.

Voltage
  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You can do the same just starting from inDegree=0 nodes and move toposort style.

»
6 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How do we solve Baker? I can't think of anything better than range queries on a merge-sort tree of convex hulls which would give $$$O(\log^2(m))$$$ or something per query, which is probably too slow to AC.

  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    By sorting queries, they take amortized $$$O(1)$$$ per node, which is $$$O(\log m)$$$ amortized per query.

    • »
      »
      »
      6 weeks ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Holy crap yeah, that's incredibly straightforward! Thank you.

    • »
      »
      »
      6 weeks ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      Could you please give me more information?

      I tried this: Each query only had one prefix, and it was always best to take a suffix of that prefix so we could do a binary search. We could take $$$x$$$ to $$$y$$$ if $$$B+(i-x+1)A \le T_i+L$$$ when I rearranged the equation, $$$T_i+(i+1)A \le Ax-B+L$$$. The left side could be calculated with a convex hull, and the right side is $$$O(1)$$$. Then I could get 60 points with $$$O(log^2 m)$$$, which means $$$T_M \le B$$$. I tried something like merge-sort tree on convex hulls and sorting the queries, but it was also $$$O(m log^2 m)$$$ and it didn't do any subtasks except the first and second.

      • »
        »
        »
        »
        6 weeks ago, hide # ^ |
        Rev. 4  
        Vote: I like it 0 Vote: I do not like it

        For each node in the merge-sort tree, we build a monotonic CHT. We partition each $$$[l,r]$$$ into $$$O(\log(m))$$$ many ranges, and maintain a vector of all the queries associated with each segment tree (or merge-sort tree) node. This allows us to answer all queries for a given node in amortized $$$O(1)$$$ time. While building up, we also run merge sort to sort the lines.

        It is not necessary to sort $$$\text{seg}[v]$$$ for each query, we can pre-sort all queries according to their $$$a$$$ value, so the complexity should be $$$O((m+q) \log(m))$$$.

        Although, even I TLE everything except the first two subtasks with this approach.

        EDIT: I managed to get 82 points (so the 22 point subtask) by using long double instead of __int128_t

        EDIT 2: Got AC! Turns out I didn't even need the merge sort because lines were already sorted by slope :facepalm:

        • »
          »
          »
          »
          »
          6 weeks ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          I'm not sure if I understand how you answer queries when you have a bunch of lines

          • »
            »
            »
            »
            »
            »
            6 weeks ago, hide # ^ |
            Rev. 2  
            Vote: I like it 0 Vote: I do not like it

            If your queries are monotonic: so something like $$$x, x+1, x+2$$$ or even $$$x, x-1, x-2$$$, we can answer queries while popping lines (which are sorted by slope themselves) from the front/back and don't need to perform a binary search to find the best line. Instead, we simply evaluate the last/first (depending on how queries are sorted) line against the line before that, and if the other line before does better, we pop the last line.

        • »
          »
          »
          »
          »
          6 weeks ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          I also cant get the last subtask even when my code is (m+q)logm :(

          My code runs in 0,7 seconds in the 22 point subtask how fast is yours?

          • »
            »
            »
            »
            »
            »
            6 weeks ago, hide # ^ |
            Rev. 3  
            Vote: I like it +11 Vote: I do not like it

            I got 100 now when I changed my segtree size to m*2 from m*4! You should try it if you also use one with size m*4

»
6 weeks ago, hide # |
 
Vote: I like it +32 Vote: I do not like it

Thanks for the problems. Some of them felt pretty annoying especially Rainfall and Festival, but I enjoyed the contests as whole.

I made all my implementations (except JOI Tour, i am yet to solve that) public on Github

  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    It's interesting to see that for Baker, when I use global arrays for queries and lines, I get TLE, but when I change it to divide and conquer, like your code, which returns vectors and takes references, I get AC in less than 1.5 seconds.

  • »
    »
    6 weeks ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    after several hours of coding and debugging, i was able to pass JOI Tour too, and i have added that to the repository. It is $$$O(M \sqrt{N} + NQ)$$$ following Kevin114514 comment