I did the problem COT2(http://www.spoj.com/problems/COT2/) using Mo's Algorithm on trees....Wondering if a solution faster than n*sqrt(n) exists?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 134 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
I did the problem COT2(http://www.spoj.com/problems/COT2/) using Mo's Algorithm on trees....Wondering if a solution faster than n*sqrt(n) exists?
| Name |
|---|



Good day to you!
Well I've done that with MO and it passed (AC).
For MO, follow this tutorial.
Then for each "move" (i.e. increase/decrease boundary of array) you shall be constant [O(1)]. The same is possible for answers.
A very good manner might be to "rename" all numbers so they will fit to 0<= Ai <= N (just sort them and rename them to indices), so you can simply operate over array.
Next thing is to choose good SQRT. Even though I guess any "normal" would do so, I've solved it with "(222)"
So the final complexity was O(Nsqrt(N)) [i.e. no maps, and no other logarithmic operations during MO]
Good Luck & Have Nice Day!
Sorry for a bit confusing language, I was asking if a solution faster than n*sqrt(n) exists or not.. Sorry for inconvenience :)
Oh I'm sorry (misunderstood that Nsqrt(N) was not enough)
Well don't know about any :'(
Auto comment: topic has been updated by virus_1010 (previous revision, new revision, compare).
Am I wrong that you are asking a question related to this problem that is one of problems from a running contest (CodeChef February Challenge 2017)?