E. Copying Data
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
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

题目链接:点击传送

思路:分块

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=2e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=1e9+;
/// 数组大小
int n,q,k;
int a[N],b[N],pos[N];
int si[N],st[N];
void update(int L,int R,int l)
{
if(pos[L]==pos[R])
{
if(si[pos[L]])
for(int i=(pos[L]-)*k+,j=st[pos[L]];i<=pos[L]*k;i++,j++)
b[i]=a[j];
si[pos[L]]=;
for(int i=L,j=;i<=R;i++,j++)
b[i]=a[l+j];
return;
}
if(si[pos[L]])
for(int i=(pos[L]-)*k+,j=st[pos[L]];i<=pos[L]*k;i++,j++)
b[i]=a[j];
si[pos[L]]=;
for(int i=L;i<=pos[L]*k;i++)
b[i]=a[l++];
for(int i=pos[L]+;i<=pos[R]-;i++,l+=k)
{
si[i]=;
st[i]=l;
}
if(si[pos[R]])
for(int i=(pos[R]-)*k+,j=st[pos[R]];i<=pos[R]*k;i++,j++)
b[i]=a[j];
si[pos[R]]=;
for(int i=(pos[R]-)*k+;i<=R;i++)
b[i]=a[l++];
}
int query(int x)
{
if(si[pos[x]])
{
int l=x-(pos[x]-)*k-;
return a[st[pos[x]]+l];
}
else
return b[x];
}
int main()
{
scanf("%d%d",&n,&q);
k=sqrt(n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]),pos[i]=(i-)/k+;
for(int i=;i<=n;i++)
scanf("%d",&b[i]);
while(q--)
{
int t;
scanf("%d",&t);
if(t==)
{
int x,y,l;
scanf("%d%d%d",&x,&y,&l);
update(y,y+l-,x);
}
else
{
int x;
scanf("%d",&x);
printf("%d\n",query(x));
}
///for(int i=1;i<=n;i++)
/// printf("%d ",query(i));
/// printf("\n");
}
return ;
}
E. Copying Data
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
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

Croc Champ 2013 - Round 1 E. Copying Data 分块的更多相关文章

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

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

  2. Croc Champ 2013 - Round 2 C. Cube Problem

    问满足a^3 + b^3 + c^3 + n = (a+b+c)^3 的 (a,b,c)的个数 可化简为 n = 3*(a + b) (a + c) (b + c) 于是 n / 3 = (a + b ...

  3. D. Connected Components Croc Champ 2013 - Round 1 (并查集+技巧)

    292D - Connected Components D. Connected Components time limit per test 2 seconds memory limit per t ...

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

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

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

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

  6. codeforces 292E. Copying Data

    We often have to copy large volumes of information. Such operation can take up many computer resourc ...

  7. CROC 2016 - Final Round [Private, For Onsite Finalists Only] C. Binary Table FWT

    C. Binary Table 题目连接: http://codeforces.com/problemset/problem/662/C Description You are given a tab ...

  8. CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 拓扑排序+二分

    题目链接: http://www.codeforces.com/contest/655/problem/D 题意: 题目是要求前k个场次就能确定唯一的拓扑序,求满足条件的最小k. 题解: 二分k的取值 ...

  9. codeforces 292E. Copying Data 线段树

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

随机推荐

  1. PHPExcel 基本用法详解

    .header header("Content-Type:application/vnd.ms-excel"); header("Content-Disposition: ...

  2. Oracle数据库返回字符类型-1~1的结果处理

    如果实体类中定义的字段是String类型,Oracle数据库中返回的是数字类型,那么Oracle返回0.xxx的时候会丢失前面的0. 要想不丢失0,那么数据库返回的就要是字符串类型的,所以要将返回值转 ...

  3. matlab 怎么建立结构体数组?

    https://zhidao.baidu.com/question/537198107.html 怎么定义一个结构体数组,使数组的每个元素是一个结构体变量.像这样:a=(1,2)a(1)=struct ...

  4. Linux系统——Keepalived高可用集群

    #### keepalived服务的三个重要功能1. 管理LVS负载均衡软件Keepalived可以通过读取自身的配置文件,实现通过更底层的接口直接管理LVS的配置以及控制服务的启动,停止功能,这使得 ...

  5. DIV CSS 绘制风车

    我得说,CSS和DIV是个有趣的东西. 由于脑袋一无聊,突然想,画个DIV风车怎么样,于是就画了一个. border的风格可以自主选择. 上代码: <style> *{ margin:0p ...

  6. redis和memcached相关

    应该选择哪一种缓存机制 redis相较于memcached更加年轻,功能更加强大. 对小型静态数据进行缓存处理,最具代表性的例子就是HTML代码片段.使用memcached所消耗内存更少. 其他情况下 ...

  7. 取n的某些位

    实例十一:取n的某些位 方法:result=(n>>4)&(~(~0<<4)) 取出某数n的低4位. 数值0  0000 0000 ~0   1111 1111 ~0& ...

  8. Trove系列(四)—Trove的快照功能介绍

    Trove 快照用于支持DbaaS 备份,复制等功能.在Trove API (guest_agent)上将支持本功能.本功能将能够支持快照,从而用来进行副本设置,主数据库克隆和备份,以及数据恢复.目前 ...

  9. python学习读取配置文件

    配置文件作为一种可读性很好的格式,非常适用于存储程序中的配置数据. 在每个配置文件中,配置数据会被分组(比如“config”和 “cmd”). 每个分组在其中指定对应的各个变量值.如下: # 定义co ...

  10. 主攻ASP.NET MVC4.0之重生:Asp.Net MVC WebApi OData

    1.新建MVC项目,安装OData Install-Package Microsoft.AspNet.WebApi.OData -Version 4.0.0 2.新建WebAPI Controller ...