博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codefroces 911G Mass Change Queries
阅读量:4680 次
发布时间:2019-06-09

本文共 2342 字,大约阅读时间需要 7 分钟。

题意翻译

给出一个数列,有q个操作,每种操作是把区间[l,r]中等于x的数改成y.输出q步操作完的数列.

输入输出格式

输入格式:

The first line contains one integer n n n ( 1<=n<=200000 1<=n<=200000 1<=n<=200000 ) — the size of array a a a .

The second line contains n n n integers a1 a_{1} a1 , a2 a_{2} a2 , ..., an a_{n} an ( 1<=ai<=100 1<=a_{i}<=100 1<=ai<=100 ) — the elements of array a a a .

The third line contains one integer q q q ( 1<=q<=200000 1<=q<=200000 1<=q<=200000 ) — the number of queries you have to process.

Then q q q lines follow. i i i -th line contains four integers l l l , r r r , x x x and y y y denoting i i i -th query ( 1<=l<=r<=n 1<=l<=r<=n 1<=l<=r<=n , 1<=x,y<=100 1<=x,y<=100 1<=x,y<=100 ).

输出格式:

Print n n n integers — elements of array a a a after all changes are made.

输入输出样例

输入样例#1:
输出样例#1:
1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 int c[800001][101]; 8 bool flag[200001][101]; 9 int n,a[200001],ans[200001];10 void build(int rt,int l,int r)11 {
int i;12 for (i=1;i<=100;i++)13 c[rt][i]=i;14 if (l==r) return;15 int mid=(l+r)/2;16 build(rt<<1,l,mid);17 build(rt<<1|1,mid+1,r);18 }19 void pushdown(int rt)20 {
int i;21 for (i=1;i<=100;i++)22 {23 c[rt<<1][i]=c[rt][c[rt<<1][i]];24 c[rt<<1|1][i]=c[rt][c[rt<<1|1][i]];25 }26 for (i=1;i<=100;i++)27 c[rt][i]=i;28 }29 void update(int rt,int l,int r,int L,int R,int x,int y)30 {
int i;31 if (l>=L&&r<=R)32 {33 for (i=1;i<=100;i++)34 if (c[rt][i]==x) c[rt][i]=y;35 return;36 }37 pushdown(rt);38 int mid=(l+r)/2;39 if (L<=mid) update(rt<<1,l,mid,L,R,x,y);40 if (R>mid) update(rt<<1|1,mid+1,r,L,R,x,y);41 }42 void query(int rt,int l,int r)43 {44 if (l==r)45 {46 ans[l]=c[rt][a[l]];47 return;48 }49 int mid=(l+r)/2;50 pushdown(rt);51 query(rt<<1,l,mid);52 query(rt<<1|1,mid+1,r);53 }54 int main()55 {
int i,q,l,r,x,y;56 cin>>n;57 for (i=1;i<=n;i++)58 {59 scanf("%d",&a[i]);60 }61 build(1,1,n);62 cin>>q;63 for (i=1;i<=q;i++)64 {65 scanf("%d%d%d%d",&l,&r,&x,&y);66 update(1,1,n,l,r,x,y);67 }68 query(1,1,n);69 for (i=1;i

 

转载于:https://www.cnblogs.com/Y-E-T-I/p/8624059.html

你可能感兴趣的文章
二分法练习1
查看>>
QT 制作串口调试小助手----(小白篇)
查看>>
前端MVC实践之hellorocket——by张舒彤
查看>>
OptimalSolution(2)--二叉树问题(3)Path路径问题
查看>>
IPC 之 Messenger 的使用
查看>>
爱情八十六课,等得不是爱情
查看>>
企业网站建设流程
查看>>
数据库的显示、创建、使用 、用户授权管理及忘记root用户后重置密码
查看>>
ES5和ES6中的继承 图解
查看>>
macos 下usb键盘问题.
查看>>
SQL函数学习(十六):STUFF()函数
查看>>
Apache Hadoop 和Hadoop生态圈
查看>>
Ctrl+Enter 选中文本提交
查看>>
android WIFI
查看>>
常用的匹配正则表达式和实例
查看>>
小组成员及其git链接
查看>>
SQL case when else
查看>>
MVc Identity登陆锁定
查看>>
cdn连接失败是什么意思_关于CDN的原理、术语和应用场景那些事
查看>>
ultraedit26 运行的是试用模式_免费试用U盘数据恢复工具 – 轻松找回U盘丢失的各种数据!...
查看>>