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 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+10,M=1e6+10,inf=2147483647;
const ll INF=1e18+10,mod=1e9+7;
///   数组大小
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]-1)*k+1,j=st[pos[L]];i<=pos[L]*k;i++,j++)
        b[i]=a[j];
        si[pos[L]]=0;
        for(int i=L,j=0;i<=R;i++,j++)
            b[i]=a[l+j];
        return;
    }
    if(si[pos[L]])
    for(int i=(pos[L]-1)*k+1,j=st[pos[L]];i<=pos[L]*k;i++,j++)
        b[i]=a[j];
    si[pos[L]]=0;
    for(int i=L;i<=pos[L]*k;i++)
        b[i]=a[l++];
    for(int i=pos[L]+1;i<=pos[R]-1;i++,l+=k)
    {
        si[i]=1;
        st[i]=l;
    }
    if(si[pos[R]])
    for(int i=(pos[R]-1)*k+1,j=st[pos[R]];i<=pos[R]*k;i++,j++)
        b[i]=a[j];
    si[pos[R]]=0;
    for(int i=(pos[R]-1)*k+1;i<=R;i++)
        b[i]=a[l++];
}
int query(int x)
{
    if(si[pos[x]])
    {
        int l=x-(pos[x]-1)*k-1;
        return a[st[pos[x]]+l];
    }
    else
        return b[x];
}
int main()
{
    scanf("%d%d",&n,&q);
    k=sqrt(n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),pos[i]=(i-1)/k+1;
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    while(q--)
    {
        int t;
        scanf("%d",&t);
        if(t==1)
        {
            int x,y,l;
            scanf("%d%d%d",&x,&y,&l);
            update(y,y+l-1,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 0;
}

 

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

 

转载于:https://www.cnblogs.com/jhz033/p/6662333.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值