Big Data Permutation
Time limit15sMemory limit2048 MB
Given an array a and a permutation b, handle point updates to a and answer queries for the longest chain a[j+1]=b[a[j]] inside [l, r] that contains the value x.
- Level
Hard9 of 10
- Topics
- Segment tree, Array, Graph
- Solved
- No attempts yet
Problem
You are given a sequence and a permutation . Process operations of the following two kinds.
- Modification: given and , change to .
- Query: given , , and , find the longest sub-interval of (that is, ) such that for every , and there is some with and . Output only the maximum length . If there is no such interval, output .
Input
The first line contains and (). The second line contains (). The third line contains (; all are distinct). Each of the next lines is either 1 x y for a modification or 2 l r x for a query (; ). There is at least one query.
Output
For each query, print the answer on its own line.