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个数 然后你需要 ...
随机推荐
- win32 消息说明
WM_NULL = $0000; WM_CREATE = $0001; 应用程序创建一个窗口 WM_DESTROY = $0002; 一个窗口被销毁 WM_MOVE = $0003; 移动一个窗口 W ...
- java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.util.JSONUtils
页面报错: root: java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.util.JSONUtils 出错 ...
- Windows中的对象
来源 http://www.0xaa55.com/forum.php?mod=viewthread&tid=1401&extra=page%3D1 windows里常用句柄操作资源 ...
- 文本域textarea显示输入剩余字数
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Python自动化环境搭建
安装配置 Eclipse + PyDev + Robotframework 集成开发环境 1.安装JDK安装目录下的jdk-7u17-windows-i586.exe文件(JAVA开发.运行环境)安装 ...
- Oracle系列:记录Record
Oracle系列:记录Record 分类: [Oracle] (15) 版权声明:本文为博主原创文章,未经博主允许不得转载. Oracle系列:记录(Record) 一,什么是记录(Record) ...
- 3.19 外协加工(通过BOM体现加工物料总成本,非系统标准工序外协功能)
3.19.1 业务方案描述 对每一个外协加工产品定义对应的加工费项目,并将发外加工物料及加工费项目一起挂在加工后产品的BOM下(供应类型为装配拉式). 加工后产品的成本按外协BOM卷积,总成本包含 ...
- (13)[Xamarin.Android] 不同分辨率下的图片使用概论
原文 [Xamarin.Android] 不同分辨率下的图片使用概论 设计Android App的时候,其尺寸众多也是一个挑战之一.要针对不同尺寸设计Android App时,就要先来了一下dpi(d ...
- [Leetcode][Python]22: Generate Parentheses
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 22: Generate Parentheseshttps://oj.leet ...
- paip.提升用户体验---论文本编辑器的色彩方案
paip.提升用户体验---论文本编辑器的色彩方案 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.ne ...