#FT0000026. Khoảng điểm xếp hạng (Rated Range)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Khoảng điểm xếp hạng (Rated Range)
Rated Range
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi plans to participate in contests, in order from contest to contest . Contest has an eligible rating interval , including both endpoints.
During contest , inspect his rating immediately before that contest. If it belongs to , the rating increases by exactly one; otherwise it remains unchanged. The resulting rating is used to determine eligibility in contest . Thus, testing every contest against the initial rating would be incorrect.
There are queries. For each independently specified initial rating , determine his rating after all contests. Each query starts anew from its own initial and uses the same contest sequence; the result of a preceding query has no effect.
Input
- Line 1: integer
n, the number of contests. - Next lines: line contains two integers
L_i R_i, the inclusive lower and upper limits of the rating interval for contest . - Next line: integer
q, the number of independent queries. - Final lines: line contains integer
X_j, the initial rating for query .
Output
Print exactly lines. Line is the final rating when query starts from rating .
Subtasks
Subtask 1 (20 points):
- .
- .
- for all .
- for all .
Subtask 2 (30 points):
- .
- .
- for all .
- for all .
Subtask 3 (50 points):
- .
- .
- for all .
- for all .
Examples
Input
5
1 5
1 3
3 6
2 4
4 7
3
3
2
5
Output
6
6
8
Explanation
The five contest rating intervals, in order, are , , , , and . Each query independently starts from its specified rating.
-
Starting at : contest 1 increases because ; contest 2 keeps because ; contest 3 increases ; contest 4 keeps ; contest 5 increases . Print
6. -
Starting at : contest 1 increases , contest 2 increases , contest 3 increases , contest 4 keeps , and contest 5 increases . Print
6. -
Starting at : contest 1 increases , contest 2 keeps , contest 3 increases , contest 4 keeps , and contest 5 increases . Print
8.
The resulting ratings are , so the output lines are 6, 6, and 8.