How can it be solved using Fenwick trees , DSU , Segment trees etc? Problem link- (http://www.spoj.com/problems/CPAIR/)
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | dXqwq | 3436 |
| 8 | Radewoosh | 3415 |
| 9 | Otomachi_Una | 3413 |
| 10 | Um_nik | 3376 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 146 |
| 3 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
How can it be solved using Fenwick trees , DSU , Segment trees etc? Problem link- (http://www.spoj.com/problems/CPAIR/)
| Name |
|---|



I solved this problem 2-3 weeks back I guess. Here is what I did:
I sorted the queries and numbers in decreasing order . Now keep DSU to keep the active segments and the segment size of each segment.
During a query you have to merge two segments and this will cause removal of two segments of some size and addition of a larger size subarray so you need a segment tree with lazy propagation for this. Each point in segment tree denotes the number of subarrays of size point index.
can u explain in a bit naive way like what are active segments which u r taking about or actually what are the segments?
if we take an 'i' then the possible 'j' which we can take are i+a,i+a+1,i+a+2,....i+b with the condition that all elements between i and j must be greater or equal to v.
So what is the significance of sorting here and what are the segments which you are referring to?
Segments = Subarrays . Whenever you iterate on a query you will get many new subarrays and it is possible older subarray say [0,1] and [3,4] can be merged due to [2,2] element is bigger than the current query... Now the active segment will be [0,4] which is the merge of older two... Now the point on segment tree tells me that number of subarrays of size= index point... We can update on merging of two segments
Sorry for bringing the old post back !!! But Can someone please tell how to do the query ???? I understood the segment part and joining ,But How to do query?? Can someone please share their ideas ??? Thanks in advance.
Why downvotes ??? Did I ask something wrong ???
Don't use a fake account to post comments.