Codeforces 292 E. Copying Data (线段树)

Posted 小坏蛋_千千

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 292 E. Copying Data (线段树)相关的知识,希望对你有一定的参考价值。

Description

We often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number array into another one, quickly.

More formally, you’ve got two arrays of integers a1,a2,...,an a 1 ,   a 2 ,   . . . ,   a n and b1,b2,...,bn b 1 ,   b 2 ,   . . . ,   b n of length n n . Also, you’ve got m queries of two types:

Copy the subsegment of array a a of length k, starting from position x x , into array b, starting from position y y , that is, execute by+q=ax+q for all integer q q (0q<k). The given operation is correct — both subsegments do not touch unexistent elements.

Determine the value in position x x of array b, that is, find value bx b x .

For each query of the second type print the result — the value of the corresponding element of array b b .

 

Input

The first line contains two space-separated integers n and m m (1n,m105) — the number of elements in the arrays and the number of queries, correspondingly. The second line contains an array of integers a1,a2,...,an a 1 ,   a 2 ,   . . . ,   a n (|ai|109) ( | a i |   ≤   10 9 ) . The third line contains an array of integers b1,b2,...,bn b 1 ,   b 2 ,   . . . ,   b n (|bi|109) ( | b i |   ≤   10 9 ) .

Next m m lines contain the descriptions of the queries. The i-th line first contains integer ti — the type of the i-th query (1ti2) ( 1   ≤   t i   ≤   2 ) . If ti=1 t i   =   1 , then the i-th query means the copying operation. If ti=2 t i   =   2 , then the i-th query means taking the value in array b b . If ti=1, then the query type is followed by three integers xi,以上是关于Codeforces 292 E. Copying Data (线段树)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 292D Connected Components (并查集)

Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C

Codeforces Codeforces Round #484 (Div. 2) E. Billiard

codeforces 598E E. Chocolate Bar(区间dp)

E. 因数串

E. Boxers ( Codeforces Round #579 )