https://codeforces.net/gym/100739/problem/A Can anyone please help me out with this problem. It has no editoial.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
https://codeforces.net/gym/100739/problem/A Can anyone please help me out with this problem. It has no editoial.
Название |
---|
You use a segment tree, but the cumuluation function should be xor instead of addition. Then you do what is written in statement, do updates and queries.
I think you have not read the problem clearly.
Yes, sorry. But now I think I have understood ;) Suggestion:
Let $$$n=j-i+1$$$ The contribution of $$$A_i$$$ is $$$n$$$ times. The contribution of $$$A_{i+1}$$$ is $$$(n-1)*2$$$ times. $$$A_k$$$ is $$$(n-k)*(k+1)$$$ times.
So for even n all contributions are even, ans=0. For odd n all $$$A_k$$$ at odd $$$k$$$ positions contribute. We can use two segment trees to store the values of even indexes in the one, and odd in the other.
Then on queries, we use dependent on the parity of $$$i$$$ the one or the other tree. Does this work or am I still missing something?
Solve for each bit separately.
The answer for a bit is then the number of subarrays that have odd sum. You can do this with a segment tree by storing some extra information in addition to the number of odd sum subarrays — the number of prefix and suffix subarrays that have odd/even sum and the total xor-sum of the subarray (these are necessary for merging). All that's left is to figure out the formulas for merging/initializing nodes and apply them. I've seen some smarter solutions (which I don't understand yet), but the slowest accepted solutions I saw using this approach ran in 1.6 seconds, which is fine.
Seconded....waiting for a solution , stuck in merging and combining approach ...