CF292E Copying Data【线段树】
来源:互联网 发布:mysql having的用法 编辑:程序博客网 时间:2024/06/02 04:34
题意:a[]、b[]两数组,有两个操作:1.用a数组的一段去替换b数组的 2.问b数组中的某个位置
思路:线段树,每个结构体记录它被覆盖的a的位置(z1),和从哪个位置开始被覆盖(z2)。查询的时候查到底层,没被覆盖,直接b[x];被覆盖,a[x-z2+z1]
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<stdlib.h>#include<math.h>#include<vector>#include<list>#include<map>#include<set>#include<stack>#include<queue>#include<algorithm>#include<numeric>#include<functional>using namespace std;typedef long long ll;typedef pair<int,int> pii;const int maxn = 2e5+5;#define lson(x) 2*x#define rson(x) 2*x+1struct data{int l,r,z1,z2;}node[maxn*4];int a[maxn],b[maxn];void build(int x,int y, int cnt){node[cnt].l = x;node[cnt].r = y;node[cnt].z1 = node[cnt].z2 = 0;if(x == y)return;int mid = (x+y) / 2;build(x,mid,lson(cnt));build(mid+1,y,rson(cnt));}void down(int cnt){if(node[cnt].z1 == 0)return;node[lson(cnt)].z1 = node[rson(cnt)].z1 = node[cnt].z1;node[lson(cnt)].z2 = node[rson(cnt)].z2 = node[cnt].z2;node[cnt].z1 = node[cnt].z2 = 0; }void up(int x,int y,int cnt,int f1,int f2){if(x == node[cnt].l && y == node[cnt].r){node[cnt].z1 = f1;node[cnt].z2 = f2;return;}down(cnt);int mid = (node[cnt].l + node[cnt].r) / 2;if(y <= mid)up(x,y,lson(cnt),f1,f2);else if(x >= mid+1)up(x,y,rson(cnt),f1,f2);else{up(x,mid,lson(cnt),f1,f2);up(mid+1,y,rson(cnt),f1,f2);}}void fid(int x,int y,int cnt){if(x == node[cnt].l && y == node[cnt].r){if(node[cnt].z1 != 0)printf("%d\n",a[x-node[cnt].z2+node[cnt].z1]);elseprintf("%d\n",b[x]);return;}down(cnt);int mid = (node[cnt].l + node[cnt].r) / 2;if(y <= mid)fid(x,y,lson(cnt));else if(x >= mid+1)fid(x,y,rson(cnt));}int main(void){int n,m;while(scanf("%d%d",&n,&m)!=EOF){for(int i = 1; i <= n; i++)scanf("%d",&a[i]);for(int i = 1; i <= n; i++)scanf("%d",&b[i]);build(1,n,1);while(m--){int op,x,y,k;scanf("%d",&op);if(op == 2){scanf("%d",&x);fid(x,x,1);}else{scanf("%d%d%d",&x,&y,&k);int tp = min(n,y+k-1);up(y,tp,1,x,y);}}}return 0;}
阅读全文
0 0
- CF292E Copying Data【线段树】
- 线段树 Codeforces292E Copying Data
- CodeForces 292E Copying Data (线段树)
- codeforces 292E Copying Data(线段树)
- 线段树(区间更新)codeforces 292E Copying Data
- CF 292E Copying Data
- codeforces 292E. Copying Data
- [CF]292E. Copying Data 分块
- Codeforces 292E(Copying Data)
- Data Structure_hdu_4217(线段树).java
- hdu4217 Data Structure? 线段树
- hdu Data Structure? 线段树
- hdu4217 Data Structure?(线段树)
- HDU 4217 Data Structure?(线段树)
- HDU4217-Data Structure?(线段树)
- hdu 2817 Data Structure? (线段树)
- HDU--4217 -- Data Structure? [线段树]
- hdu-4217-Data Structure? 线段树
- 如何自己编写Makefile
- Python中append()和extend()的区别,pop()和remove()的区别
- 重新认识font-size、line-height和行高
- leetcode-448. Find All Numbers Disappeared in an Array
- AndroidStudio gradle配置
- CF292E Copying Data【线段树】
- 实例解析二维数组与数组指针
- linux 基础学习5
- 模块化编程
- 内存映射MMAP和DMA
- Kth Smallest Number in Multiplication Table
- 30. Substring with Concatenation of All Words
- 单例模式
- PyCharm20171025测试激活码可用http://xidea.online