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个数 然后你需要 ...
随机推荐
- sqlserver 死锁查看辅助存储过程
USE [master] GO /****** Object: StoredProcedure [dbo].[sp_who_lock] Script Date: 03/23/2016 14:17:49 ...
- EF实体框架-从数据库更新模型 一部分表的外键(导航属性)无法显示
从数据库更新模型 要想让数据库表之间的外键关系 显示到实体模型的导航属性中去. 表的外键 对应另一张表的字段要是主键,唯一键显示不出来
- Eclipse下运行拷贝的项目,更改项目名后报404
右键项目->Properties->Web Project Settings 将“Context root”改为你的项目名称
- C++多态的实现原理
1. 用virtual关键字申明的函数叫做虚函数,虚函数肯定是类的成员函数. 2. 存在虚函数的类都有一个一维的虚函数表叫做虚表.类的对象有一个指向虚表开始的虚指针.虚表是和类对应的,虚表指针是和对象 ...
- std::string转化大小写(C++)
#include <string> #include <algorithm> void test() { std::string strA="QQQQWWWqqqqq ...
- <转>eclipse如何修改dynamic web module version .
--------------------------------------------------------------------------------------------- 原 ...
- Android SD卡创建文件和文件夹失败
原文:Android SD卡创建文件和文件夹失败 功能需要,尝试在本地sd卡上创建文件和文件夹的时候,报错,程序崩溃. 一般情况下,是忘记给予sd卡的读写权限.但是这里面权限已经给了,还是报错. 在网 ...
- (11)Xamarin.iOS - 新增iPhone storyboard
原文 Xamarin.iOS - 新增iPhone storyboard 1. 开启Xamarin Studio 并建立新项目 专案类型为 iOS=>iPhone Storyboard => ...
- rsyslog 传输mysql 日志
在另外一种环境中,让我们假定你已经在机器上安装了一个名为"foobar"的应用程序,它会在/var/log下生成foobar.log日志文件.现在,你想要将它的日志定向到rsysl ...
- Python的迭代器(iterator)和生成器(constructor)
一.迭代器(iterator) 1.迭代器的概述 在Python中,for循环可以用于Python中的任何类型,包括列表.元祖等等,实际上,for循环可用于任何“可迭代对象”,这其实就是迭代器 迭代器 ...