~欢迎你!第 AmazingCounters.com 位造访者

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

复制代码
Copying Data
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
 
Description
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:

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.
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 Input

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

这个题目很无语,读题读了块一个小时,发现不知道怎么去成段替换觉得用lazy不适合,后来日天大神跟我讲了一下用lazy的方法,秒懂。

但是写着写着发现有点乱了思路,又重新写了一遍写了1个小时,过了样例后WA了一次,不知道调哪里,然后自己跟着题目注释,突然发现lazy的变化规律越来越清晰。

果然思路混乱就去打注释才是最好的方法!

下面是写了我一个下午加晚上的题目的AC代码:


 

  

复制代码

 

posted @   ~HDMaxfun  阅读(181)  评论(0编辑  收藏  举报
编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· 软件产品开发中常见的10个问题及处理方法
· Vite CVE-2025-30208 安全漏洞
· MQ 如何保证数据一致性?
· 《HelloGitHub》第 108 期
点击右上角即可分享
微信分享提示