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个数 然后你需要 ...
随机推荐
- 使用trim方法检测用户输入
首先需要封装trim方法,可以去除字符串两端空格的方法 function trim(str) { return str.replace(/^\s+|\s+$/g, ""); } 获 ...
- Request和Response详解
转自:http://zhidao.baidu.com/link?url=8BI0cjlcFdBSJKHTZlpo874eqtbTJoZfrh3miQgM_05RvSER8skPiBc1wSPZtXT8 ...
- (转)IE劫持原理 BHO
为什么“浏览器劫持”能够如此猖狂呢?放眼众多论坛的求助贴,我们不时可以看到诸如“我的IE被主页被改了,我用杀毒工具扫了一遍都没发现病毒,我把主页改回自己的地址,可是一重启它又回来了!”.“我的系统一开 ...
- 学习python 一些错误记录
1. TypeError: 'unicode' object is not callable当遇到这样的错误时候, 一般是属性当做方法调用了,比如,selenium 脚本, driver.title ...
- fckeditor使用详解
FCKEditor是一个很好的用于Web页面中的格式化文本编译控件.现在越来越多的论坛的发帖页面中更多的使用了这个控件,我们这里将如何在基于Java的web开发中使用FCKEditor控件的步骤提供给 ...
- 移动web开发
在现代网页开发中,新增了一个移动设备网页开发,在这样的需求下,你需要考虑如何将移动web和pc web同步处理 /* * 浏览器如何识别移动设备 * */ var ua = navigator.use ...
- Js把URL中的参数解析为一个对象
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title&g ...
- windbg命令学习2
一.windbg查看内存命令: 当我们在调试器中分析问题时, 经常需要查看不同内存块的内容以分析产生的原因, 并且在随后验证所做出的假设是否正确. 由于各个对象的状态都是保存在内存中的, 因此内存的内 ...
- HTML5学习笔记之客户端存储数据方法:localStorage(),sessionStorage()
HTML5提供了两种在客户端存储数据的新方法: localStorage():没有时间限制的数据存储 sessionStorage():针对一个session的数据存储 下面的一个例子用localSt ...
- Ubuntu eclipse :An error has occurred. See the log file
安装eclipse: sudo apt-get install eclipse-platform 调整java: sudo update-alternatives --config java 启动: ...