Codeforces 292E. Copying Data

Source: Internet
Author: User

We often has to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you is advised to come up with a-to-copy some part of a number array into another one, qui Ckly.

More formally, you ' ve got the arrays of integers a1,? a 2,?...,? a N and b1,? b 2,?...,? b N of lengthN. Also, you ' ve gotmQueries of types:

  1. Copy the subsegment of arrayaof lengthk, starting from positionx, into arrayb, starting from positiony, that's, execute by? +? Q? =? a x? +? q For all integerQ(0?≤? ) Q. <? k). The given operation is Correct-both subsegments does not touch unexistent elements.
  2. Determine the value in position x of array b, which is, find value bx.

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

Input

The first line contains space-separated integersNandm(1?≤? ) N,? m. ≤?105)-the number of elements in the arrays and the number of queries, correspondingly. The second line contains an array of integers a1,? a 2,?...,? a N (| Ai|? ≤?109). The third line contains an array of integers b1,? b 2,?...,? b N (| bi|? ≤?109).

NextmLines contain the descriptions of the queries. TheI-th line First contains integer Ti -the type of theI-th Query(1?≤? ) Ti? ≤?2). If Ti? =?1, then theI-th query means the copying operation. If Ti? =?2, then theI-th query means taking the value in arrayb. If Ti? =?1, then the query type was followed by three integers xi,? y i,? k I (1?≤? ) xi,? y i,? k i? ≤? n)-the parameters of the copying query. If Ti? =?2, then the query type was followed by integer xi (1?≤? ) xi? ≤? n)-the position in arrayb.

All numbers in the lines is separated with a single spaces. It is guaranteed and all the queries be correct, that's, the copying borders fit into the borders of arrays a and b.

Output

For each second type query print, the result on a, single line.

Sample Test (s) input
5 101 2 0-1 33 1 5-2 02 51 3 3 32 52 42 11 2 1 42 12 41 4 2 12 2
Output
03-1323-1
This problem can be done with segment tree segments and new, belong to a class of color line tree topic, you can define two variable STRA,STRB. Stra Indicates whether this segment is covered by the a[] array, if there is no overlay, then stra=0, if overridden, the range of intervals covered by a[] is A[STRA]~A[STRA+K-1],STRB, but the beginning of the record is b[].
For Operation 1, enter X1,y1,k, as long as the interval [y1,y1+k-1] stra becomes x1,strb into Y1.
For Operation 2, enter X1, look in the line segment tree, if this (ie [x1,x1]) stra is 0, output C[X1], otherwise output A[X1+STRB-STRA].
#include <stdio.h> #include <string.h> #define MAXN 100006int a[maxn],c[maxn];int st1,st2,x1,y1,k;struct node{int L,R,STRA,STRB;} b[4*maxn];void Build (int l,int r,int i) {int mid;b[i].l=l;b[i].r=r;b[i].stra=b[i].strb=0;if (l==r) return;Mid= (L+R)/2;Build (L,MID,I*2);Build (mid+1,r,i*2+1);} void update (int l,int r,int i)//stra=x1,strb=y1; {int mid;if (b[i].stra==x1 && b[i].strb==y1) return;if (b[i].l==l && b[i].r==r) {B[i].stra=x1;b[i].strb=y1;return;}if (b[i].stra!=-1) {B[i*2].stra=b[i*2+1].stra=b[i].stra;B[I*2].STRB=B[I*2+1].STRB=B[I].STRB;B[i].stra=b[i].strb=-1;}Mid= (B[I].L+B[I].R)/2;if (r<=mid) update (L,R,I*2);else if (l>mid) update (L,R,I*2+1);else {Update (l,mid,i*2); update (MID+1,R,I*2+1);}}void question (int id,int i) {int mid;if (b[i].stra!=-1) {St1=b[i].stra;st2=b[i].strb;return;}Mid= (B[I].L+B[I].R)/2;if (Id<=mid) question (id,i*2);else question (id,i*2+1);} int main () {int n,m,i,j,h,d,e,f,x;while (scanf ("%d%d", &n,&m)!=eof){for (i=1;i<=n;i++) {scanf ("%d", &a[i]);}for (i=1;i<=n;i++) {scanf ("%d", &c[i]);}Build (1,n,1);while (m--) {scanf ("%d", &h);if (h==1) {scanf ("%d%d%d", &x1,&y1,&k);Update (y1,y1+k-1,1);}else if (h==2) {scanf ("%d", &x);st1=st2=0;Question (x,1);if (st1==0) {printf ("%d\n", c[x]); continue;}else {printf ("%d\n", A[x-st2+st1]); continue;}}}}return 0;}

Codeforces 292E. Copying Data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.