Mi Teleférico

시간 제한2초메모리 제한2048 MB

요약
각 관광객이 예산 안에서 회사 구간 패스를 다른 구간으로 바꿔 1번 역에서 모든 역에 도달할 수 있는지 판정한다.
난이도

어려움10점 중 9점

유형
그래프, BFS, 그리디, 정렬
정답자
아직 제출이 없습니다

문제

La Paz, the capital city of Bolivia, is famous as a tourist spot and for an aerial cable car called Mi Teleférico. You are now visiting La Paz for sightseeing, and you want to visit as many sightseeing places as possible. In this task, we consider the following simplified situation.

There are NN aerial cable car stations in La Paz, numbered from 11 to NN in ascending order of altitude. There are MM one-way lines, numbered from 11 to MM. There are PP aerial cable car companies, numbered from 11 to PP. Each line is managed by a single company. Line ii (1≤i≤M1 ≤ i ≤ M) is operated from station A_iA\_i to station B_iB\_i, and is managed by the company C_iC\_i. Here, the line always runs from the lower altitude station to the higher altitude station. In other words, A_i<B_iA\_i < B\_i holds.

The Bureau of transportation of La Paz issued unlimited ride passes for convenience. Each ride pass contains 22 integers ll, rr, which satisfy 1≤l≤r≤P1 ≤ l ≤ r ≤ P. The pass enables the possessor to ride lines, which are managed by any one of company l,l+1,…,rl, l + 1, \dots ,r. In other words, for an integer ii which satisfies 1≤i≤M1 ≤ i ≤ M, the pass enables the possessor to ride line ii when l≤C_i≤rl ≤ C\_i ≤ r holds. It is possible to use a single pass for several lines. Let a ride pass (l,r)(l,r) denote this ride pass.

Now, QQ tourists, numbered from 11 to QQ, visit La Paz. Tourist jj (1≤j≤Q1 ≤ j ≤ Q) has a ride pass (L_j,R_j)(L\_j, R\_j) and X_jX\_j boliviano cash.

Each tourist’s goal is to ensure that no station cannot be travelled from station 11, using only lines that can be ridden with the ride pass he or she has. Tourist jj (1≤j≤Q1 ≤ j ≤ Q) can exchange his or her ride pass described in the following process to achieve their goal. Here, each tourist can exchange at most once.

  1. He or she chooses 22 integers l′l', r′r', which satisfy 1≤l′≤r′≤P1 ≤ l' ≤ r' ≤ P.
  2. He or she exchanges a ride pass (L_j,R_j)(L\_j, R\_j) for a ride pass (l′,r′)(l', r'). It costs ∣L_j−l′∣+∣R_j−r′∣|L\_j − l'| + |R\_j − r'| boliviano as a fee.

Your purpose is to determine, for each tourist, whether or not he or she can achieve his or her goal within the cash he or she has.

Write a program which, given information about stations, lines, and tourists, determines whether or not he or she can achieve his or her goal within the cash he or she has for each tourist.

입력

Read the following data from the standard input.

 NN MM PP 

 A_1A\_1 B_1B\_1 C_1C\_1 

 A_2A\_2 B_2B\_2 C_2C\_2 

 ⋮\vdots 

 A_MA\_M B_MB\_M C_MC\_M 

 QQ 

 L_1L\_1 R_1R\_1 X_1X\_1 

 L_2L\_2 R_2R\_2 X_2X\_2 

 ⋮\vdots 

 L_QL\_Q R_QR\_Q X_QX\_Q

출력

Write QQ lines to the standard output. On the jj-th line (1≤j≤Q1 ≤ j ≤ Q), output Yes if tourist jj can achieve his or her goal, and No otherwise.

제한

  •  2≤N≤300,0002 ≤ N ≤ 300\\, 000.
  •  1≤M≤300,0001 ≤ M ≤ 300\\, 000.
  •  1≤P≤1091 ≤ P ≤ 10^9.
  •  1≤A_i<B_i≤N1 ≤ A\_i < B\_i ≤ N (1≤i≤M1 ≤ i ≤ M).
  •  1≤C_i≤P1 ≤ C\_i ≤ P (1≤i≤M1 ≤ i ≤ M).
  •  1≤Q≤400,0001 ≤ Q ≤ 400\\, 000.
  •  1≤L_j≤R_j≤P1 ≤ L\_j ≤ R\_j ≤ P (1≤j≤Q1 ≤ j ≤ Q).
  •  0≤X_j≤1090 ≤ X\_j ≤ 10^9 (1≤j≤Q1 ≤ j ≤ Q).
  • Given values are all integers.

예제4

  1. 예제 1

    입력
    4 6 10
    1 2 3
    2 4 7
    1 2 6
    2 3 5
    3 4 2
    3 4 8
    4
    3 7 0
    5 6 0
    3 4 0
    1 9 0
    
    예상 출력
    Yes
    No
    No
    Yes
    
  2. 예제 2

    입력
    4 6 10
    1 2 3
    2 4 7
    1 2 6
    2 3 5
    3 4 2
    3 4 8
    3
    5 6 10
    3 4 1
    7 8 3
    
    예상 출력
    Yes
    No
    Yes
    
  3. 예제 3

    입력
    3 1 1000000000
    1 2 6
    1
    1 1000000000 1000000000
    
    예상 출력
    No
    
  4. 예제 4

    입력
    5 9 2000
    2 3 1814
    2 3 457
    1 2 1226
    3 4 1354
    1 5 1050
    1 2 1725
    2 3 1383
    1 5 1626
    1 4 1795
    5
    850 1872 128
    82 428 1217
    487 924 573
    1639 1926 202
    202 420 25
    
    예상 출력
    Yes
    Yes
    Yes
    Yes
    No