Croc Champ 2013 - Round 1 E. Copying Data 线段树
题目链接:
http://codeforces.com/problemset/problem/292/E
E. Copying Data
time limit per test2 secondsmemory limit per test256 megabytes
#### 问题描述
> 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 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.
#### 输入
> 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.
#### 输出
> For each second type query print the result on a single line.
####样例输入
> 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
样例输出
0
3
-1
3
2
3
-1
题意
给你大小为n的两个数组,a,b;
执行两个操作:
1,x,y,k,把a数组中以x开头长度为k的串覆盖到b数组中以y开头的长度为k的位置。
2,x, 查询b[x];
题解
对于查询1在b数组上做成段覆盖更新:(y,y+k-1),值为查询的id。然后对于查询2做单点查询,查到对应的查询再去a数组中找对应的位置。
代码
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
const int maxn=1e5+10;
int setv[maxn<<2];
void pushdown(int o){
if(setv[o]!=-1){
setv[lson]=setv[rson]=setv[o];
setv[o]=-1;
}
}
int qp,qv;
void query(int o,int l,int r){
if(l==r||setv[o]!=-1){
qv=setv[o];
}else{
if(qp<=mid) query(lson,l,mid);
else query(rson,mid+1,r);
}
}
int ul,ur,uv;
void update(int o,int l,int r){
if(ul<=l&&r<=ur){
setv[o]=uv;
}else{
pushdown(o);
if(ul<=mid) update(lson,l,mid);
if(ur>mid) update(rson,mid+1,r);
}
}
struct Node{
int x,y,k;
Node(int x,int y,int k):x(x),y(y),k(k){}
Node(){}
}que[maxn];
int a[maxn],b[maxn];
int n,m;
void init(){
clr(setv,-1);
}
int main() {
scf("%d%d",&n,&m);
init();
for(int i=1;i<=n;i++) scf("%d",&a[i]);
for(int i=1;i<=n;i++) scf("%d",&b[i]);
ul=1,ur=n,uv=0;
update(1,1,n);
for(int i=1;i<=m;i++){
int cmd; scf("%d",&cmd);
if(cmd==1){
int x,y,k;
scf("%d%d%d",&x,&y,&k);
que[i]=Node(x,y,k);
ul=y,ur=y+k-1,uv=i;
update(1,1,n);
}else{
int x; scf("%d",&x);
qp=x;
query(1,1,n);
int ans;
if(qv==0) ans=b[x];
else ans=a[x-que[qv].y+que[qv].x];
prf("%d\n",ans);
}
}
return 0;
}
//end-----------------------------------------------------------------------
Croc Champ 2013 - Round 1 E. Copying Data 线段树的更多相关文章
- 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 ...
- ACM: Copying Data 线段树-成段更新-解题报告
Copying Data Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description W ...
- 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 ...
- D. Connected Components Croc Champ 2013 - Round 1 (并查集+技巧)
292D - Connected Components D. Connected Components time limit per test 2 seconds memory limit per t ...
- codeforces 292E. Copying Data 线段树
题目链接 给两个长度为n的数组, 两种操作. 第一种, 给出x, y, k, 将a[x, x+k-1]这一段复制到b[y, y+k-1]. 第二种, 给出x, 输出b[x]的值. 线段树区间更新单点查 ...
- [BZOJ 3110] [luogu 3332] [ZJOI 2013]k大数查询(权值线段树套线段树)
[BZOJ 3110] [luogu 3332] [ZJOI 2013]k大数查询(权值线段树套线段树) 题面 原题面有点歧义,不过从样例可以看出来真正的意思 有n个位置,每个位置可以看做一个集合. ...
- Educational Codeforces Round 6 E dfs序+线段树
题意:给出一颗有根树的构造和一开始每个点的颜色 有两种操作 1 : 给定点的子树群体涂色 2 : 求给定点的子树中有多少种颜色 比较容易想到dfs序+线段树去做 dfs序是很久以前看的bilibili ...
- Codeforces Round #426 (Div. 2) D 线段树优化dp
D. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard inp ...
- MemSQL Start[c]UP 2.0 - Round 1 F - Permutation 思维+线段树维护hash值
F - Permutation 思路:对于当前的值x, 只需要知道x + k, x - k这两个值是否出现在其左右两侧,又因为每个值只有一个, 所以可以转换成,x+k, x-k在到x所在位置的时候是否 ...
随机推荐
- 13JavaScript运算符
运算符 = 用于给 JavaScript 变量赋值. 算术运算符 + 用于把值加起来 实例 指定变量值,并将值相加: y=5; z=2; x=y+z; 在以上语句执行后,x 的值是:7 1.JavaS ...
- java爬虫爬取网页内容前,对网页内容的编码格式进行判断的方式
近日在做爬虫功能,爬取网页内容,然后对内容进行语义分析,最后对网页打标签,从而判断访问该网页的用户的属性. 在爬取内容时,遇到乱码问题.故需对网页内容编码格式做判断,方式大体分为三种:一.从heade ...
- Home Assistant系列 -- 基于树莓派安装并设置自启动
Home Assistant 是当前智能家居最火热的开源DIY 软件,之前的文章 智能家居系统 Home Assistant 系列 --介绍篇 已经详细介绍过了,这里就不详细介绍了,今天介绍 如何 ...
- 前端chrome调试
Resources标签页 Resources标签页可以查看到请求的资源情况,包括CSS.JS.图片等的内容.也可以设置各种断点.对存储的内容进行编辑然后保存也会实时的反应到页面上. 几个常用的断点快捷 ...
- java入门---运算符&算术运算符&自增自减运算符&关系运算符&位运算符
计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操纵变量.我们可以把运算符分成以下几组: 算术运算符 关系运算符 位运算符 逻辑运算符 赋值运算符 ...
- 20155239 2016-2017-2 《Java程序设计》第10周学习总(2017-04-22 16:26
教材学习 1.基本概念划分 OIS的七层协议: 应用层.表示层.会话层.运输层.网络层.数据链路层.物理层. OIS的五层协议: 应用层.运输层.网络层.数据链路层.物理层. 由下往上介绍如下: 2. ...
- 20155337 2016-2017-2 《Java程序设计》第一周学习总结
20155337 2016-2017-2 <Java程序设计>第一周学习总结 教材学习内容总结 我们主要学习的是JAVA SE平台也就是标准平台-Java SE四个组成部分:JVM .JR ...
- centos7.5yum安装mysql(官方yum源比较慢)
mysql的部署 查看Linux发行版本 cat /etc/redhat-release 下载MySQL官方的Yum Repository wget -i http://dev.mysql.com/g ...
- Dlib简介及在windows7 vs2013编译过程
Dlib是一个C++库,包含了许多机器学习算法.它是跨平台的,可以应用在Windows.Linux.Mac.embedded devices.mobile phones等.它的License是Boos ...
- day 2 异常传递 ,抛出
1.异常的传递 def test1(): print("---test1--") print(num) print('---test1 over---') def test2(): ...