codeforces 292E. Copying Data 线段树
给两个长度为n的数组, 两种操作。
第一种, 给出x, y, k, 将a[x, x+k-1]这一段复制到b[y, y+k-1]。
第二种, 给出x, 输出b[x]的值。
线段树区间更新单点查询, 第一种操作, 就将线段树的[y, y+k-1]这一段赋值为i, i是第i个询问, 并将这个询问存到一个数组里。
第二种操作, 查询位置x处的值是多少, 做相应的修改就好..
感觉不是很难但还是写了好久
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 1e5+;
int sum[maxn<<], cover[maxn<<], a[maxn], b[maxn];
void pushDown(int rt) {
if(cover[rt]) {
if(cover[rt<<]<cover[rt])
cover[rt<<] = cover[rt];
if(cover[rt<<|]<cover[rt])
cover[rt<<|] = cover[rt];
cover[rt] = ;
}
}
void update(int L, int R, int val, int l, int r, int rt) {
if(L<=l&&R>=r) {
cover[rt] = val;
return ;
}
pushDown(rt);
int m = l+r>>;
if(L<=m)
update(L, R, val, lson);
if(R>m)
update(L, R, val, rson);
}
int query(int p, int l, int r, int rt) {
if(l == r) {
return cover[rt];
}
pushDown(rt);
int m = l+r>>;
if(p<=m)
return query(p, lson);
else
return query(p, rson);
}
pll q[maxn];
int main()
{
int n, m, x, y, k, sign;
cin>>n>>m;
for(int i = ; i<=n; i++)
scanf("%d", &a[i]);
for(int i = ; i<=n; i++) {
scanf("%d", &b[i]);
}
for(int i = ; i<=m; i++) {
scanf("%d", &sign);
if(sign == ) {
scanf("%d", &x);
int tmp = query(x, , n, );
if(tmp!=) {
y = q[tmp].se;
b[x] = a[q[tmp].fi+x-y];
}
printf("%d\n", b[x]);
} else {
scanf("%d%d%d", &x, &y, &k);
q[i] = mk(x, y);
update(y, y+k-, i, , n, );
}
}
return ;
}
codeforces 292E. Copying Data 线段树的更多相关文章
- ACM: Copying Data 线段树-成段更新-解题报告
Copying Data Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description W ...
- Croc Champ 2013 - Round 1 E. Copying Data 线段树
题目链接: http://codeforces.com/problemset/problem/292/E E. Copying Data time limit per test2 secondsmem ...
- codeforces 292E. Copying Data
We often have to copy large volumes of information. Such operation can take up many computer resourc ...
- Buses and People CodeForces 160E 三维偏序+线段树
Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...
- CodeForces 877E DFS序+线段树
CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身 ...
- [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)
[Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...
- [Codeforces 1199D]Welfare State(线段树)
[Codeforces 1199D]Welfare State(线段树) 题面 给出一个长度为n的序列,有q次操作,操作有2种 1.单点修改,把\(a_x\)修改成y 2.区间修改,把序列中值< ...
- [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)
[Codeforces 316E3]Summer Homework(线段树+斐波那契数列) 顺便安利一下这个博客,给了我很大启发(https://gaisaiyuno.github.io/) 题面 有 ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
随机推荐
- webview的配置
WebSettings的常用方法介绍 WebSettings 通过webview获得WebSettings 调用WebSettings 的方法,配置webview WebSettings webSet ...
- Python核心编程读笔 2
第三章 python基础 一.语句和语法 \n 标准的行分隔符 \ 继续上一行 ; 将两个语句连接在一行 : 分开代码块的头和体 代码块以缩进块的形式体现 python文件以模块的形式组织 二.变量赋 ...
- (跨平台)cocos2d-x C++ or Object-C(前端)调用C# webservices(后台),实现交叉编译到Android/IOS/WinPhone等移动终端设备
1.2014年4月2号算是正式找到自己的实习工作-杭州美迪软件有限公司(移动物联事业部)合作于:四川管家婆总部移动终端代理,由于在校选编程专业语言C#和在浙大网新培训课程(C#.Asp.net开发)缘 ...
- Linux学习之wget命令
Linux系统中的wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,我们经常要下载一些软件或从远程服务器恢复备份到本地服务器.wget支持HTTP,HTTPS和FTP协 ...
- QF——关于iOS的强引用,弱引用及strong,retain,copy,weak,assignd的关系
强引用和弱引用: 我们已经知道OC中的内存管理是通过“引用计数器”来实现的.一个对象的生命周期取决于它是否还被其他对象引用(是否retainCount=0).但在有些情况下,我们并不希望对象的销毁时间 ...
- spring 源码之 ioc 容器的初始化和注入简图
IoC最核心就是两个过程:IoC容器初始化和IoC依赖注入,下面通过简单的图示来表述其中的关键过程:
- JS倒计时器一只,顺便复习javascript时间相关函数
window.onload = function(){ var uS = 604800; //后台提供 : 秒 var day=hour=minute=second=0, timer; var dem ...
- WebService之Axis2
写在前面 本文只说Axis2的用法. 1.下载与部署 需要下载两个文件: 下载地址:http://mirrors.cnnic.cn/apache/axis/axis2/java/core/1.7.1/ ...
- Windows2008 VPN登录
上一章已经讲过Windows2008RT搭建VPN服务器搭建过程,接下来说一下win2008和win8的VPN登录 win8VPN连接过程 先说win2008的VPN登录过程.很简单: 打开网络和共享 ...
- <meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cac ...