#GL0000304. Hành lang vòng tròn (Round Corridor)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hành lang vòng tròn (Round Corridor)
Round Corridor
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A circular corridor consists of two concentric rings. The inner ring has equal sectors numbered clockwise. The outer ring has equal sectors numbered in the same direction.
There are walls between adjacent sectors of the same ring, but no wall separates the inner and outer rings, so a person may move between rings wherever no wall blocks the path. The twelve-o’clock position is a wall boundary for both rings.
For each of independent queries, determine whether a person can move from sector to sector without passing through a wall.
Input
The first line contains : the sector counts of the two rings and the number of queries.
Each of the next lines contains . The ring identifiers are or , while are sector indices within the specified rings.
Output
For each query, print YES if the destination is reachable and NO otherwise, preserving query order.
Subtasks
- Subtask 1 (20 points): ; ; ; if , otherwise ; if , otherwise .
- Subtask 2 (30 points): ; ; ; if , otherwise ; if , otherwise .
- Subtask 3 (50 points): ; ; ; if , otherwise ; if , otherwise .
Examples
Example 1
Input
4 6 3
1 1 2 3
2 6 1 2
2 6 2 4
Output
YES
NO
YES
Explanation
There are connected components. Each component contains two consecutive inner sectors or three consecutive outer sectors. Query 1: and belong to group , so YES. Query 2: is in group but is in group , so NO. Query 3: and are both in group , so YES.