当前位置: 首页 > news >正文

codefroces 911G Mass Change Queries

题意翻译

给出一个数列,有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: 复制
5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5
输出样例#1: 复制
5 2 5 4 5
维护100颗线段树$c[rt][i]=j$,表示在这个区间里i颜色变成j
区间修改,将修改下传
初始$c[rt][i]=i$
至于下传状态:
$c[L(rt)][i]=c[rt][c[L(rt)][i]]$
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 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<n;i++)
70     printf("%d ",ans[i]);
71   cout<<ans[n]<<endl;
72 }

 

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

相关文章:

  • Chrome浏览器几个好用的插件
  • SQL——两个表之间的更新:用一个表的字段更新另一个表的字段
  • [root]既然sudo 可以暂时获取root权限,那么为何还需要root这个用户呢
  • A*,IDA*,Dijkstra
  • AES对上传文件解密并加密的实现(JAVA实现)
  • Utilities之EXPIMP小结
  • HPU 1166: 阶乘问题(一)
  • Utilities之EXPIMP小结-续1
  • [原创]Zabbix3.4_API的python示例
  • VC程序异常中断的原因
  • POJ 2331 Water pipe IDA*
  • 软件问题
  • POJ 3460 Booksort IDA*
  • SpringCloud系列八:自定义Ribbon配置
  • 结构之法算法之道blog最新博文集锦第6期CHM文件0积分下载
  • 002-读书笔记-JavaScript高级程序设计 在HTML中使用JavaScript
  • JavaScript 无符号位移运算符 三个大于号 的使用方法
  • Laravel 菜鸟晋级之路
  • leetcode388. Longest Absolute File Path
  • node入门
  • PAT A1017 优先队列
  • Python_OOP
  • Rancher-k8s加速安装文档
  • Spring Security中异常上抛机制及对于转型处理的一些感悟
  • springboot_database项目介绍
  • uva 10370 Above Average
  • Vim Clutch | 面向脚踏板编程……
  • webpack项目中使用grunt监听文件变动自动打包编译
  • 百度小程序遇到的问题
  • 不上全站https的网站你们就等着被恶心死吧
  • 初探 Vue 生命周期和钩子函数
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 看完九篇字体系列的文章,你还觉得我是在说字体?
  • 融云开发漫谈:你是否了解Go语言并发编程的第一要义?
  • 小程序测试方案初探
  • 应用生命周期终极 DevOps 工具包
  • 分布式关系型数据库服务 DRDS 支持显示的 Prepare 及逻辑库锁功能等多项能力 ...
  • # Java NIO(一)FileChannel
  • #Linux(帮助手册)
  • #pragma预处理命令
  • (编译到47%失败)to be deleted
  • (附源码)springboot掌上博客系统 毕业设计063131
  • (四)docker:为mysql和java jar运行环境创建同一网络,容器互联
  • (万字长文)Spring的核心知识尽揽其中
  • (轉貼) 資訊相關科系畢業的學生,未來會是什麼樣子?(Misc)
  • .NET BackgroundWorker
  • .NET CF命令行调试器MDbg入门(二) 设备模拟器
  • .NET CORE 3.1 集成JWT鉴权和授权2
  • .NET Core Web APi类库如何内嵌运行?
  • .net访问oracle数据库性能问题
  • .NET运行机制
  • /dev下添加设备节点的方法步骤(通过device_create)
  • @angular/cli项目构建--http(2)
  • @Autowired多个相同类型bean装配问题
  • @data注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)