Task A: 【LAR-1】01101
One solution is to use the Polland-Rho method. Check P4718【模板】Pollard-Rho.
Std does not use that method. It uses Sieve of Eratosthenes to find primes that are less than or equal to . Since , the amount of those primes are actually less than (the actual amount is ).
Then use these primes to test each if . The total time would be , which would be able to pass this task.
Task B: 【LAR-1】Abbreviation
Actually this is the template of Trie (even easier than that).
Task C: 【LAR-1】Balanced Tree I
A completely balanced tree would be a complete binary tree. It is easy to use bitwise operations to judge if there exists an integer such that .
Task D: 【LAR-1】Balanced Tree II
It is easy to find out that the minimum height is the minimum integer such that . One possible construction is to make the sizes of the three sons equal as much as possible.
Task E: 【LAR-1】Desert Explore
An easy interaction. In order to determine the upper left corner of the ancient city, we can go through the first line and go back, go through the second line and go back, …
The operation we printed should be like this:
1 1
DDDD...DAAAA...A S
DDDD...DAAAA...A S
...
DDDD...DAAAA...A (the last line)The second time we do the opposite:
n m
AAAA...ADDDD...D W
AAAA...ADDDD...D W
...
AAAA...ADDDD...D (the first line)And it will be easy to calculate and .
Task F: 【LAR-1】Finite and Infinite
Just simulate what the task asks you to do. -bit integer type is enough.
Task G: 【LAR-1】Yet Another Mahjong Problem
A searching problem. First find the required tiles. Divide the tiles into or to find a required tile.
Calculate the sum of unused required tiles to get the answer.