i started to thinking about segment tree to solve this problem.

But after i noticed the range [0, 10^8], i just stucked there and couldn't managed how to solve it. please help ... thnx in advance :) :)

# | User | Rating |
---|---|---|

1 | tourist | 3602 |

2 | LHiC | 3287 |

3 | Radewoosh | 3266 |

4 | W4yneb0t | 3181 |

5 | TakanashiRikka | 3178 |

6 | moejy0viiiiiv | 3122 |

7 | izrak | 3109 |

8 | anta | 3105 |

8 | Um_nik | 3105 |

8 | ershov.stanislav | 3105 |

# | User | Contrib. |
---|---|---|

1 | rng_58 | 178 |

2 | csacademy | 167 |

3 | tourist | 165 |

4 | Errichto | 164 |

4 | Petr | 164 |

6 | Swistakk | 158 |

7 | matthew99 | 152 |

8 | Zlobober | 151 |

9 | zscoder | 143 |

10 | GlebsHP | 137 |

i started to thinking about segment tree to solve this problem.

But after i noticed the range [0, 10^8], i just stucked there and couldn't managed how to solve it. please help ... thnx in advance :) :)

↑

↓

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Aug/20/2017 08:52:11 (c2).

Desktop version, switch to mobile version.

User lists

Name |
---|

You have to think about the

amount of distinct numbersyou have (at most: 2 × 50 000 for the ranges, plus 50 000 for the query points).For example, if I give you these ranges: [1, 60 000 000], [40 000 000, 90 000 000] and these query points: 1 000 000, 50 000 000, 100 000 000, then you can reduce the problem (without changing the final answer) to a smaller problem. In this case, the ranges become: [1, 5], [3, 6], and the query points become: 2, 4, 7. For "both problems", the answers are 1, 2, 0.

P.S. note that (once you solved the "reduction" part) you can solve this problem also by using a binary indexed tree (with a trick I explained here) which can be easier than a range tree.

yeah,i got it. Thanx again :) :)

I don't understand how to do the reduction part. How you reduce this one -> [1, 60 000 000], [40 000 000, 90 000 000] and these query points: 1 000 000, 50 000 000, 100 000 000 to this one [1, 5], [3, 6], and the query points become: 2, 4, 7 Both are quite different. isn't it?

To compress numbers you can replace a certain number with its index in sorted array, for example: [1, 6, 28, 5], sorted array is [1, 5, 6, 28], so you will get new array [0, 2, 3, 1], don't forget that equal numbers must be equal in new array too.

Thanks for Your Reply. I understand now.