题意翻译

给出一个数列,有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: 复制
$c[L(rt)][i]=c[rt][c[L(rt)][i]]$

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int c[][];
bool flag[][];
int n,a[],ans[];
void build(int rt,int l,int r)
{int i;
for (i=;i<=;i++)
c[rt][i]=i;
if (l==r) return;
int mid=(l+r)/;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
}
void pushdown(int rt)
{int i;
for (i=;i<=;i++)
{
c[rt<<][i]=c[rt][c[rt<<][i]];
c[rt<<|][i]=c[rt][c[rt<<|][i]];
}
for (i=;i<=;i++)
c[rt][i]=i;
}
void update(int rt,int l,int r,int L,int R,int x,int y)
{int i;
if (l>=L&&r<=R)
{
for (i=;i<=;i++)
if (c[rt][i]==x) c[rt][i]=y;
return;
}
pushdown(rt);
int mid=(l+r)/;
if (L<=mid) update(rt<<,l,mid,L,R,x,y);
if (R>mid) update(rt<<|,mid+,r,L,R,x,y);
}
void query(int rt,int l,int r)
{
if (l==r)
{
ans[l]=c[rt][a[l]];
return;
}
int mid=(l+r)/;
pushdown(rt);
query(rt<<,l,mid);
query(rt<<|,mid+,r);
}
int main()
{int i,q,l,r,x,y;
cin>>n;
for (i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
build(,,n);
cin>>q;
for (i=;i<=q;i++)
{
scanf("%d%d%d%d",&l,&r,&x,&y);
update(,,n,l,r,x,y);
}
query(,,n);
for (i=;i<n;i++)
printf("%d ",ans[i]);
cout<<ans[n]<<endl;
}

codefroces 911G Mass Change Queries的更多相关文章

  1. Mass Change Queries CodeForces - 911G (线段树合并)

    链接 大意: 给定序列, 每次操作将区间[l,r]中的x全改为y, 最后输出序列 权值范围比较小, 对每个权值开一颗线段树, 每次将x合并到y上即可 #include <iostream> ...

  2. Mass Change Queries Codeforces - 911G

    https://codeforces.com/contest/911/problem/G 没想到线段树合并还能这么搞.. 对每个权值建一个线段树(动态开点),如果权值为k的线段树上第i位为1,那么表示 ...

  3. [CF911G]Mass Change Queries

    题目大意: 给你一个长度为n的数列a,按顺序进行以下m次操作,每次将区间[l,r]中的所有x变成y,问最后数列是怎样的. 思路: 线段树. 每个线段树结点上维护当前区间每个数分别会变成多少.时间复杂度 ...

  4. CF911G Mass Change Queries(线段树+暴力)

    cf机子真的快. 其实这个题的维护的信息还是很巧妙的. 首先,观察到题目中涉及到,区间修改这个操作,然后最后只查询一次,我们不妨用线段树来维护这个过程. 但是貌似直接维护每个位置的值可能不太好维护. ...

  5. Educational Codeforces Round 35

    Nearest Minimums 相同的数里最小的数里的最小距离 Solution Two Cakes Solution Three Garlands 瞎比试 Solution Inversion C ...

  6. How To Do Master Record Mass Maintenance

    How To Do Master Record Mass Maintenance Which master records mass maintenance can be done? What do ...

  7. SAP事务码 一

    SE80 -- edit source code. SE24 -- class create or display. SFP -- created and maintained independent ...

  8. 解析大型.NET ERP系统 十三种界面设计模式

    成熟的ERP系统的界面应该都是从模板中拷贝出来的,各类功能的界面有规律可遵循.软件界面设计模式化或是艺术性的创作,我认可前者,模式化的界面客户容易举一反三,降低学习门槛.除了一些小部分的功能界面设计特 ...

  9. Database Schemas Found in Oracle E-Business Suite

    https://docs.oracle.com/cd/E26401_01/doc.122/e22952/T156458T659606.htm Table of Database Schemas in ...

随机推荐

  1. 【R语言系列】作图入门示例一

    假设有如下数据,我们使用plot函数作图 月龄 体重 月龄 体重  1 4.4 9 7.3 3 5.3 3 6.0 5 7.2 9 10.4 2 5.2 12 10.2 11 8.5 3 6.1 R语 ...

  2. Android实验报告

    实验名称:Android程序设计 实验时间:2017.5.24 实验人员:20162309邢天岳(结对同学20162313苑洪铭) 实验目的:使用android stuidio开发工具进行基本安卓软件 ...

  3. Flask 学习 五 电子邮件

    pip install mail from flask_mail import Mail # 邮件配置 app.config['MAIL_SERVER']='smtp.qq.com' app.conf ...

  4. css中的position

    一.position语法与结构 position语法: position : static absolute relative position参数:static : 无特殊定位,对象遵循HTML定位 ...

  5. 从同步阻塞聊到Java三种IO方式

    本文总结自 https://zhuanlan.zhihu.com/p/34408883, https://www.zhihu.com/question/19732473中愚抄的回答, http://b ...

  6. 零基础大数据入门教程:Java调用阿里云短信通道服务

    这里我们使用SpringBoot 来调用阿里通信的服务. 阿里通信,双11.收到短信,日发送达6亿条.保障力度非常高. 使用的步骤: 1.1. 第一步:需要开通账户 1.2. 第二步:阅读接口文档 1 ...

  7. kafka和mqtt的区别是什么?

    两者都是从传统的Pub/Sub消息系统演化出来的,但是进化方向不一样,比较如下: Kafka是为了数据集成的场景,与以往Pub/Sub消息总线不一样,通过分布式架构提供了海量消息处理.高容错的方式存储 ...

  8. KNN算法简单应用

    这里是写给小白看的,大牛路过勿喷. 1 KNN算法简介 KNN(K-Nearest Neighbor)工作原理:存在一个样本数据集合,也称为训练样本集,并且样本集中每个数据都存在标签,即我们知道样本集 ...

  9. 重启Apache报错

    重启Apache报错,如图所示:server: /etc/httpd/modules/mod_jk.so: wrong ELF class: ELFCLASS64 原因:mod_jd的版本有问题 解决 ...

  10. python与mongodb的交互 增删改差

    首先引入包: pip install pymongo需要用到如下对象: MongoClient对象:用于与MongoDB服务器建立连接 client=MongoClient('主机ip',端口) Da ...