Page 1 of 1

11525 - Permutation

Posted: Sun Oct 12, 2008 4:26 pm
by Ron
I am getting TLE.
My approach is simple. I am using n-times delete function to delete a value which is already used for print.
Is it right way ?

Re: 11525 - Permutation

Posted: Sun Oct 12, 2008 6:13 pm
by pvncad
You can improve the algorithm further. You don't need to n iterations to find what to print.

Hint: skip the numbers in block

-pvncad

Re: 11525 - Permutation

Posted: Sun Oct 12, 2008 7:11 pm
by Ron
my code gives TLE.

Code: Select all

AC

EDIT : Thank you all for advice

Re: 11525 - Permutation

Posted: Mon Oct 13, 2008 12:07 am
by Leonid
I used binary tree to solve the problem.

Re: 11525 - Permutation

Posted: Mon Oct 13, 2008 9:41 am
by pvncad
Hint: split the vectors into smaller ones so that you search and removal time reduces.

Re: 11525 - Permutation

Posted: Mon Oct 13, 2008 7:40 pm
by Robert Gerbicz
Leonid wrote:I used binary tree to solve the problem.
More precisely it's possible to solve this problem by interval tree (this is also a binary tree) in O(N*log(N)) time and in O(N) memory.

Re: 11525 - Permutation

Posted: Mon Oct 20, 2008 10:50 am
by Chimed
Done both idea

Using binary tree and splitting to subarrays.
But didn't understand why subarray method is faster than the other? Was it good test for this idea or generally it holds. Anyway best method might use binary tree because it is safe and usefull afterward.

Re: 11525 - Permutation

Posted: Fri Oct 31, 2008 3:19 pm
by wahaha
should i use BigNum in this problem, i think if n = k! it's a very very big number.

another question is if this problem should use BigNum, it seems O(klgk) is not fast enough in my solution .

i need some help.

Re: 11525 - Permutation

Posted: Tue Jun 09, 2009 10:18 am
by roticv
There is no need to compute factorials. Just find the kth smallest number that is not used (k starts from 0...so-on).

People have suggested using interval/segment trees to solve this problem. I've used fenwick trees to solve it. It is possible to find the kth smallest number using binary search.

Re: 11525 - Permutation

Posted: Tue Jul 28, 2009 5:52 pm
by lionking
I don't understand why this problem can use interval tree to solve it?

Could anyone give me some hint, plz?