this is a temporary version.
fix many bugs.
now the pre-processing use O(n * log(n) ^ 2),
which may be improved.