Yosupo's Algorithm
Time limit4sMemory limit1024 MB
Given red and blue weighted points, answer each query by picking a red and a blue point that satisfy the y-order and L, R split conditions, maximizing their total weight.
- Level
Hard8 of 10
- Topics
- Sorting, Segment tree
- Solved
- No attempts yet
Problem
...Can you replicate my master thesis in 5 hours?
Yosupo
You are given red points and blue points on a two dimensional plane. The -th red point's coordinate is , and its weight is . The -th blue point's coordinate is , and its weight is .
Process queries. In the -th query, you are given two integers and , and choose a red point and a blue point with the following conditions:
- ( and ) or ( and )
Maximize the sum of weights of the two points, or report that it is impossible to select two points.
Input
Input is given from Standard Input in the following format:
Output
For each query, print the maximum sum of weights of the selected points on its own line, or if it is impossible to choose two points.
Constraints
- are all distinct
- are all distinct