Old Orhei

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

요약
정점 수가 50 이하인 그래프에서 함수들의 수열을 구간마다 시작 정점에 적용한 결과를 구하고, 수열의 원소를 갱신하는 문제.
난이도

어려움10점 중 9점

유형
세그먼트 트리, 그래프, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Old Orhei (Orheiul Vechi) is a natural and historical complex located on a narrow bend of the Răut River. It consists of NN archaeological vestiges and MM one-way roads between some pairs of vestiges. Every road has a unique index between 11 and MM, defined by the input order in which it is given. Please refer to the Examples section for visualizing such a configuration.

Recently an array left by the Cucuteni–Trypillia civilization was discovered by the local scientists. The array consists of TT integers with values between 11 and MM. In order to figure out the mystical meaning of this array, the new intern will be instructed to follow this procedure:

At the beginning, the intern starts at some initial archaeological vestige. The other scientists start broadcasting to him a contiguous sub-array of the main array (first broadcasting the first element of the subarray, then the second one, and so on). The intern then changes his location depending on the following rules:

  • If the intern can use the road indexed with the current broadcast number (in other words, the intern's current location is equal to the starting point of the corresponding road), the intern traverses it (goes to the end-point of the corresponding road).
  • Otherwise the intern does nothing, and remains in his current location.

With the occasion of the 88-th European Junior Olympiad in Informatics, the local scientists have asked you to help them perform the following QQ queries:

  • 11 LL RR SS - the scientists want to know what will be the final location of the intern if initially he is located in the SS-th vestige, and only the contiguous sub-array of the initial array which starts at index LL and ends at index RR is broadcasted.
  • 22 ii KK - the scientists override the ii-th element of the array with the value KK. The change is permanent. (In other words, the array changes so that A_i=KA\_i = K after performing the query).

Your task is to answer correctly to all the queries of type 11.

입력

The first line contains two space-separated integers NN and MM, the number of archaeological vestiges and one-way roads.

The next MM lines contain the description of the roads. In particular, line i will contain two space-separated numbers indicating that the ii-th road starts in X_iX\_i and ends in Y_iY\_i. There can exist roads for which X_i=Y_iX\_i = Y\_i as well as pairs of roads for which X_i=X_jX\_i = X\_j , Y_i=Y_jY\_i = Y\_j but i≠ji \ne j.

The next line contains an integer TT, the length of the found array.

The next line contains TT space-separated integers A_1,A_2,…,A_TA\_1 ,A\_2, \dots ,A\_T, representing the array elements.

The next line contains an integer QQ, the number of queries.

The next QQ lines contain the query description:

  • 11 LL RR SS for a query of type 11.
  • 22 ii KK for a query of type 22.

출력

For each query of type 11 output the answer on a separate line.

제한

  • 1≤N≤501 ≤ N ≤ 50
  • 1≤M,T,Q≤1051 ≤ M,T,Q ≤ 10^5
  • 1≤X,Y≤N1 ≤ X ,Y ≤ N
  • 1≤A≤M1 ≤ A ≤ M
  • 1≤L≤R≤T1 ≤ L ≤ R ≤ T
  • 1≤S≤N1 ≤ S ≤ N
  • 1≤i≤T1 ≤ i ≤ T
  • 1≤K≤M1 ≤ K ≤ M

예제3

  1. 예제 1

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

    입력
    3 3
    1 2
    2 3
    3 1
    4
    3 1 1 2
    4
    1 1 2 3
    2 2 2
    1 1 2 3
    1 1 4 2
    
    예상 출력
    2
    1
    3
    
  3. 예제 3

    입력
    2 3
    1 1
    1 2
    1 2
    4
    1 1 2 3
    3
    1 1 2 1
    2 1 2
    1 1 2 1
    
    예상 출력
    1
    2