# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
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 |
Name |
---|
Auto comment: topic has been updated by code_tycoon (previous revision, new revision, compare).
Seems solvable with a simple segment tree.
Maintain sum of triplets, sum of pairs, and sum of elements in each node of a segment tree. Merging nodes should be pretty straightforward.
can u elaborate a bit on the merging part in the segment tree.
Say you're merging two nodes a and b, into res.
res.triplets = a.triplets + b.triplets + (a.pairs * b.sum) + (a.sum * b.pairs)
res.pairs = a.pairs + b.pairs + a.sum * b.sum
res.sum = a.sum + b.sum
Initialize single element nodes with (0, 0, arr[i]).
I'm not sure how to explain the general process, but try defining what you're trying to calculate into simpler things, even if it means defining new things to store. For e.g. in triplets, either they'll be completely on left or right side, or 2 will be on one side, one on the other. How do you get product of 2 at a time? They can be both on left, both right, or one each side. Keep doing until you have merging logic for all things you store in your segment tree nodes.
Do these for a bit of practice:
https://www.spoj.com/problems/GSS1/ https://www.spoj.com/problems/GSS3/ https://www.spoj.com/problems/GSS5/ https://www.codechef.com/problems/HARRYGOF
thanks it worked!! Here is the link to the solution if someone wants to refer: https://pastebin.com/ixKP3Ugk