I tried this problem using segment tree but it's getting TLE. Can anybody explain how to remove TLE from this code?
Solution : https://pastebin.com/8iuk4mQp
Problem : http://www.spoj.com/problems/PATULJCI/
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
I tried this problem using segment tree but it's getting TLE. Can anybody explain how to remove TLE from this code?
Solution : https://pastebin.com/8iuk4mQp
Problem : http://www.spoj.com/problems/PATULJCI/
Название |
---|
Well, i don't see why this code should pass. There are simple alternatives than trying to squeeze a heavy-constant segment tree anyway, but if you still want to, you can read. I was able to pass with a Merge Sort Tree in szkopul using some constant optimization, code here. There is a simple solution using the fact that the element appears > 1/2 in the range, we can try to pick random a number between [L,R] and see if in the range, this number appears more than 1/2 times using a histogram, the probability of error is if you try k numbers
I read that editorial but still couldn't get past the TLE. By the way that codechef question got AC. Thanks for help
Can you explain the probability idea more clearly as I am not aware about it
Just random generate index between L and R ~30 times and see if the number this index represent appears more than 1/2 in subarray [L,R]
Thanks for the idea