No.670 log is a Constant
Problem Statement
You are given a sequence $a_i$ of length $N$ and $Q$ queries. Each query is as follows.
- Given $x$, find the number of elements of ${a_i}$ that are less than $x$.
Note that the sizes of the sequence and the number of queries are given in the input, but their contents are both generated by a random number generator.
For the output, let $r_i$ be the result of the $i(i = 1,2,...,Q)$-th query, and
print the xor of all $r_i \times (i-1)$.
That is, let $s_i = r_i \times (i-1)$, and print $s_1 \oplus s_2 \oplus ... \oplus s_Q$.
The query results are combined in order to reduce the time spent on output (the intended solution does obtain the answers to all queries).
A naive solution to this problem (code that outputs the correct answer but takes a very long time to run) is provided for three languages, C++, Java, and D. Refer to it for how the input is generated. For these three languages, there are intended solutions that fit within the time limit. (C++: 1461ms, Java: 3627ms (what?), D: 2721ms)
Source code
Input
N Q Seed
$N = 2 \times 10^5$
$Q = 5 \times 10^7$
$1 \leq Seed \leq 10^9$
$0 \leq a_i, x \leq 2^{31} - 1$
Output
Print a newline at the end.
Sample
Sample 1
Input
3 5 100
Output
11
$\{a_i\} = \{574298591, 668652393, 1255298759\}$, and the queries are, in order,
$1374848783, 844241532, 121207337, 1805629405, 534777954$.
This case does not satisfy the input constraints.
Sample 2
Input
50000 100000 1194
Output
5935406007
The provided naive solution can still run at this size. (It may take several tens of seconds.)
This case does not satisfy the input constraints either.
Sample 3
Input
200000 50000000 2525
Output
4959527808339
If you run the provided naive solution on this case, it is doubtful that the result will come back before the contest ends. Please be careful.
This case satisfies the input constraints.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
yosupot
sigma425