题目大意:

给定两个长度为n(1~10^5)的数组a[]和数组b[],有两个操作。

1: 1 x y k,令b[y+q]=a[x+q] (0<=q<k)

2: 2 x, 问当前的b[x]的值。

最多操作次数m为10^5.

区间更新,单点查询。

AC Code
 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 #define lson l,m,rt<<1
 5 #define rson m+1,r,rt<<1|1
 6 #define maxn 100001
 7 int a[maxn],b[maxn];
 8 struct node{
 9     int cnt,y;
10 }setree[maxn<<2];
11 void build(int l,int r,int rt)
12 {
13     setree[rt].cnt=0;
14     setree[rt].y=0;
15     if(l==r)
16     return;
17     int m=(l+r)>>1;
18     build(lson);
19     build(rson);
20 }
21 void pushdown(int rt)
22 {
23     if(setree[rt].cnt){
24         setree[rt<<1].y=setree[rt].y;
25         setree[rt<<1].cnt=setree[rt].cnt;
26         setree[rt<<1|1].y=setree[rt].y;
27         setree[rt<<1|1].cnt=setree[rt].cnt;
28         setree[rt].y=0;
29         setree[rt].cnt=0;
30     }
31 }
32 void update(int l,int r,int rt,int L,int R,int c)
33 {
34     if(L<=l&&r<=R){
35         setree[rt].y=L;
36         setree[rt].cnt=c;
37         return;
38     }
39     int m=(l+r)>>1;
40     pushdown(rt);
41     if(L<=m)
42     update(lson,L,R,c);
43     if(R>m)
44     update(rson,L,R,c);
45 }
46 int query(int l,int r,int rt,int num)
47 {
48     if(l==r){
49         if(setree[rt].cnt==0)
50         return 0;
51         return setree[rt].cnt+num-setree[rt].y;
52     }
53     int m=(l+r)>>1;
54     pushdown(rt);
55     if(num<=m)
56     return query(lson,num);
57     else
58     return query(rson,num);
59 }
60 int main()
61 {
62     int n,m;
63     scanf("%d%d",&n,&m);
64     for(int i=1;i<=n;i++)
65     scanf("%d",a+i);
66     for(int i=1;i<=n;i++)
67     scanf("%d",b+i);
68     build(1,n,1);
69     while(m--){
70         int op;
71         scanf("%d",&op);
72         if(op==1){
73             int x,y,k;
74             scanf("%d%d%d",&x,&y,&k);
75             update(1,n,1,y,y+k-1,x);
76         }
77         else{
78             int num;
79             scanf("%d",&num);
80             int ans=query(1,n,1,num);
81             if(ans==0)
82             printf("%d\n",b[num]);
83             else
84             printf("%d\n",a[ans]);
85         }
86     }
87 }