report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Water troughs - MarisaOJ: Marisa Online Judge

Water troughs

Time limit: 2000 ms
Memory limit: 256 MB
There are $n$ water troughs in a 2D plane. The $i$-th trough is a line segment connecting $(x_{i1}, y_{i1})$ and $(x_{i2}, y_{i2})$. All troughs are inclined ($y_{i1} \ne y_{i2}$). A marble falls vertically from $(x, 10^6)$. When it hits a trough, it rolls to the lower end, then falls vertically again, until it hits $y=0$. **Task**: Given $q$ queries, each providing a starting $x$ coordinate. Find the final $x$ coordinate where the marble hits the ground ($y=0$). #### Input - First line: $n$ ($1 \le n \le 10^5$). - Next $n$ lines: $x_1, y_1, x_2, y_2$. - Next line: $q$ ($1 \le q \le 10^5$). - Next line: $q$ integers representing starting $x$. #### Output - Print $q$ integers separated by space. #### Example Input: ``` 4 1 3 4 2 3 4 5 5 8 1 11 2 7 5 10 3 3 5 6 8 ``` Output: ``` 4 6 8 ``` #### Subtasks - **Subtask 1 (50 points)**: $n, q \le 1000$. - **Subtask 2 (50 points)**: No additional constraints.
PTNK Team Selection Test [2025 - 2026]
Balanced subarray
Construct number
Orthogonal pairs
Bubble sort
Optimal subset
Water troughs
Topic
2026
Rating 800
Solution (0) Solution