Ladies and Gentlemen, please help me -> problem.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Ladies and Gentlemen, please help me -> problem.
Название |
---|
Let's first forget about given array, imagine it's filled with zeroes. Now, you only need to find out how much was added to i-th position.
Let's do a following trick: store not how much was added to the i-th position, but how much was added to all positions, divisable by i. Let's store it in some array called add[i]. Now notice that add[l..r] += x is exactly the second type of queries we need to process.
The only thing we have to figure out is how to answer the first type of queries. It's quite simple. Let vector divisors[i] be all divisors of number i. Now, to find answer, you just have to do answer += add[x], for all x in divisors[i], and then asnwer += a[i], where a[i] is value of i-th position in initial array. You can estimate amount of divisors of i like i^(1/3) * 2 (it's a well known fact).
Complexity of this solution will be O(n^(1/3)) for first query and O(sqrt(n)) for second if you use sqrt-decomposition, and O(n^(1/3) * log n) for first query and O(log n) for second if you use segment tree/fenwick tree.
Here's my solution: http://pastebin.com/MNfqHFD0
You can actually get to sqrt(N) for update and cuberoot(N) for query if you use sqrt decomposition for processing range updates. http://ideone.com/W3LNJJ
Thank you too =) I heard, that this problem can be solved in O(q * log(N)). If you know, can you share solution idea?
I'll give it a bit more time but I can't think of a solution that fast :(
Good job)
Thank you.