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 and b1, b2, ..., bn of
length n. Also, you've got m queries of two types:

  1. Copy the subsegment of array a of length k, starting
    from position x, into array b, starting from position y,
    that is, execute by + q = ax + q for
    all integer q (0 ≤ q < k). The given operation
    is correct — both subsegments do not touch unexistent elements.
  2. Determine the value in position x of array b, that
    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 two space-separated integers n and m (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, a2, ..., an (|ai| ≤ 109).
The third line contains an array of integers b1, b2, ..., bn (|bi| ≤ 109).

Next m lines contain the descriptions of the queries. The i-th
line first contains integer ti —
the type of the i-th query (1 ≤ ti ≤ 2).
If ti = 1, then
the i-th query means the copying operation. If ti = 2,
then the i-th query means taking the value in array b.
If ti = 1, then
the query type is followed by three integers xi, yi, ki (1 ≤ xi, yi, ki ≤ n) —
the parameters of the copying query. If ti = 2,
then the query type is followed by integer xi (1 ≤ xi ≤ n) —
the position in array b.

All numbers in the lines are separated with single spaces. It is guaranteed that all the queries are correct, that is, 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 10
1 2 0 -1 3
3 1 5 -2 0
2 5
1 3 3 3
2 5
2 4
2 1
1 2 1 4
2 1
2 4
1 4 2 1
2 2
output
0
3
-1
3
2
3
-1
题意:给你两个数字序列a[]和b[],有两种操作,一种是把起点为xi,长度为k的a[]的一段复制给以yi为起点,长度为k的b[],还有一种操作是询问当前b[x]的数字是什么。
思路:
这道题可以用线段树成段更新做,属于染色一类线段树题目,可以这么想,对于任意一个数,记录它有没有被a[]的其中一段覆盖了,如果被覆盖了,可以记录它被覆盖的a[]的那段的起点stra以及b[]被覆盖的起点strb,如果被覆盖,那么最后结果就是a[x1+strb-stra]。stra表示这一线段是否被a[]数组覆盖,如果没有覆盖,那么stra=0,如果覆盖,那么被a[]覆盖的区间范围是a[stra]~a[stra+k-1],strb同理,只不过记录的是b[]的开始位置。
对于操作1,输入x1,y1,k,只要使得区间[y1,y1+k-1]的stra变成x1,strb变成y1.
对于操作2,输入x1,在线段树中寻找,如果这一点(即[x1,x1])的stra是0,就输出c[x1],否则输出a[x1+strb-stra].

#include<stdio.h>
#include<string.h>
#define maxn 100006
int 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的更多相关文章

  1. codeforces 292E. Copying Data 线段树

    题目链接 给两个长度为n的数组, 两种操作. 第一种, 给出x, y, k, 将a[x, x+k-1]这一段复制到b[y, y+k-1]. 第二种, 给出x, 输出b[x]的值. 线段树区间更新单点查 ...

  2. Croc Champ 2013 - Round 1 E. Copying Data 线段树

    题目链接: http://codeforces.com/problemset/problem/292/E E. Copying Data time limit per test2 secondsmem ...

  3. ACM: Copying Data 线段树-成段更新-解题报告

    Copying Data Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description W ...

  4. Croc Champ 2013 - Round 1 E. Copying Data 分块

    E. Copying Data time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. E. Copying Data 解析(線段樹)

    Codeforce 292 E. Copying Data 解析(線段樹) 今天我們來看看CF292E 題目連結 題目 給你兩個陣列\(a,b\),有兩種操作:把\(a\)的一段複製到\(b\),或者 ...

  6. Codeforces 950.E Data Center Maintenance

    E. Data Center Maintenance time limit per test 1 second memory limit per test 512 megabytes input st ...

  7. 14.8.4 Moving or Copying InnoDB Tables to Another Machine 移动或者拷贝 InnoDB 表到另外机器

    14.8.4 Moving or Copying InnoDB Tables to Another Machine 移动或者拷贝 InnoDB 表到另外机器 这个章节描述技术关于移动或者复制一些或者所 ...

  8. 14.6.2 Moving or Copying InnoDB Tables to Another Machine 移动或者copy InnoDB 表到另外的机器

    14.6.2 Moving or Copying InnoDB Tables to Another Machine 移动或者copy InnoDB 表到另外的机器 这个章节描述技术关于移动或者copy ...

  9. [Windows Azure] Data Management and Business Analytics

    http://www.windowsazure.com/en-us/develop/net/fundamentals/cloud-storage/ Managing and analyzing dat ...

随机推荐

  1. Ts有限状态机

    ts版本的有限状态机 最近做小游戏要做切换人物状态,花点时间写了一个有限状态机,使用语言为Ts,也可改成自己的语言 按照目前的逻辑,这个可以继续横向扩展,某些做流程管理 先上预览图 Fsm:状态机类 ...

  2. SpringBoot启动报端口已被占用--解决

    问题 启动SpringBoot项目后发现启动失败,控制台输出以下内容 Description: The Tomcat connector configured to listen on port 81 ...

  3. 隐马尔科夫模型(HMM)原理详解

    隐马尔可夫模型(Hidden Markov Model,HMM)是可用于标注问题的统计学习模型,描述由隐藏的马尔可夫链随机生成观测序列的过程,属于生成模型.HMM在语音识别.自然语言处理.生物信息.模 ...

  4. Linux 防火墙基于 CentOS7 的防火墙操作命令

    防火墙服务操作命令 重启防火墙 systemctl restart firewalld 查看防火墙状态 systemctl status firewalld 开启.关闭.重启防火墙 # 开启 serv ...

  5. 【Linux】rsh进程缓慢问题处理

    环境CentOS 6.5 由于项目上线时间很长,服务器持续很久没有关机重启过,随后发现rsh反应特别慢 rsh登陆服务器的反应最慢时候3分钟才可以建立链接,登陆之后查看服务器负载是否正常,查看cpu, ...

  6. 小试牛刀ElasticSearch大数据聚合统计

    ElasticSearch相信有不少朋友都了解,即使没有了解过它那相信对ELK也有所认识E即是ElasticSearch.ElasticSearch最开始更多用于检索,作为一搜索的集群产品简单易用绝对 ...

  7. SAP 摘录数据集

    要在报表中创建并填充摘录数据集,需要执行三步骤:1.将要在摘录数据集中使用的记录类型定义为字段组FIELD-GROUPS该语句定义了字段组,字段组可以将几个字段组合到一个名称下,字段组不为字段保留存储 ...

  8. SAP FTP FOR ABAP programing

    近来忙的不可开交,忙的一塌糊涂,呵呵,今天怀揣愧疚之心,上来分享博文一篇,算是对自己的一点安慰.   首先在SAP系统中提供了很多的FTP示例程序,如下: RSFTP001         SAPFT ...

  9. 求得二叉搜索树的第k小的元素

    求得二叉搜索树的第k小的元素 给定一个二叉搜索树,编写一个函数 kthSmallest 来查找其中第 k 个最小的元素. 须知:二叉搜索树,又叫二叉排序树,二叉查找树.特点是:左子树的所有元素都小于等 ...

  10. (Oracle)数据库用户的密码过期时间如何修改为永不过期

    Oracle的密码过期规则是用Profile来管理的,系统默认只有一个Profile(DEFAULT),该profile的密码过期规则为180天.那么如何修改Oracle数据库用户的密码过期时间为永不 ...