t3jtex's blog

By t3jtex, history, 8 months ago, In English

668948A - Square Root

Solution
Code

668948B - Rectangle

Solution
Code

668948C - Common Prime Factor

Solution
Code

668948D - xyab

Solution
Code

668948E - Coins

Solution
Code

668948F - f(x)

Solution
Code
  • Vote: I like it
  • +2
  • Vote: I do not like it

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by t3jtex (previous revision, new revision, compare).

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by t3jtex (previous revision, new revision, compare).

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I'm too lazy to implement this, but F could be solved in O(n) without bin lifting through the following process:

For each connected component, find the cycle, and select a random node in the cycle. Assign it a value of zero, and go backwards through the cycle, assigning each node with the value of its "parent" + 1, call this the node number. For each node not in the cycle, let dist be the number of moves to get into the cycle, and x be the node number of first node in the cycle it reaches. The node number of this node is (x + dist) % cycle_length. Then, for each query, check if they're in the same connected component (can be done in amortized O(1) with DSU if you treat it like an undirected graph, but it's also possible to just use DFS / BFS), and if so, check if they have the same node number.

This is inspired by the recent USACO Gold contest, sadly didn't get any points on this problem though :(.