Logo
(追記) (追記ここまで)

23691번 - Osumnjičeni 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB1811975.000%

문제

In a police investigation, n suspects were identified and now it’s up to the witnesses to try to find the perpetrator. The height of every suspect i was measured, but due to the unreliability of measurement, it is known only that their height is a real number from the interval from li to ri (inclusive). At most one of the suspects is the perpetrator, and it could be the case that none of them are.

A signle lineup consists of choosing two positive integers a and b (1 ≤ a ≤ b ≤ n), then taking the suspects a, a + 1, ..., b to a separate room so that the witnesses could try to identify the perpetrator. As the witnesses could be confused if two of the suspects have the same height, a lineup is allowed only if it is possible to guarantee that no two suspects will have the same height. During a lineup, the witnesses will always be able to identify the perpetrator if he is among the chosen suspects, or they will be able to tell that he is not among them.

The lead investigator is now interested in answering questions of the following form: “If I were certain that the label of the perpetrator could only be between p and q (p ≤ q), what is the minimum number of lineups needed in the worst case so that the witnesses are able to find the perpetrator, or report that he is not among the suspects?” Help the lead investigator answer q of such questions.

입력

The first line contains a positive integer n, the number of suspects.

The following n lines contain two positive integers li and ri (1 ≤ li ≤ ri ≤ 109) which represent the possible height range of the suspect with label i.

The next line contains a positive integer q, the number of questions.

The following q lines contain two positive integers pi and qi (1 ≤ pi ≤ qi ≤ n) which determine a question.

출력

In q lines print the answers to the corresponding questions: the minimum required number of lineups.

제한

In every subtask, it holds that 1 ≤ n, q ≤ 200 000.

서브태스크

번호배점제한
110

q = 1, p1 = 1, q1 = n

210

1 ≤ n ≤ 5000, 1 ≤ q ≤ 5000

320

1 ≤ n ≤ 5000, 1 ≤ q ≤ 200 000

420

1 ≤ n ≤ 200 000, 1 ≤ q ≤ 100

550

No additional constraints.

예제 입력 1

2
1 1
1 1
3
1 1
2 2
1 2

예제 출력 1

1
1
2

예제 입력 2

3
1 1
2 2
3 3
3
1 1
2 3
1 3

예제 출력 2

1
1
1

예제 입력 3

5
1 3
3 3
4 6
2 3
1 1
3
1 4
3 5
1 5

예제 출력 3

3
1
3

힌트

Clarification of the third example:

For the first and the third question, it is sufficient to have three lineups: one consists of the suspect 1, one consists of the suspects 2 and 3, and one consists of the suspects 4 and 5.

For the second question, it is sufficient to have one lineup which consists of the suspects 3, 4 and 5.

출처

Contest > Croatian Open Competition in Informatics > COCI 2021/2022 > Contest #2 5번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /