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.
输入输出样例
#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的更多相关文章
- Mass Change Queries CodeForces - 911G (线段树合并)
链接 大意: 给定序列, 每次操作将区间[l,r]中的x全改为y, 最后输出序列 权值范围比较小, 对每个权值开一颗线段树, 每次将x合并到y上即可 #include <iostream> ...
- Mass Change Queries Codeforces - 911G
https://codeforces.com/contest/911/problem/G 没想到线段树合并还能这么搞.. 对每个权值建一个线段树(动态开点),如果权值为k的线段树上第i位为1,那么表示 ...
- [CF911G]Mass Change Queries
题目大意: 给你一个长度为n的数列a,按顺序进行以下m次操作,每次将区间[l,r]中的所有x变成y,问最后数列是怎样的. 思路: 线段树. 每个线段树结点上维护当前区间每个数分别会变成多少.时间复杂度 ...
- CF911G Mass Change Queries(线段树+暴力)
cf机子真的快. 其实这个题的维护的信息还是很巧妙的. 首先,观察到题目中涉及到,区间修改这个操作,然后最后只查询一次,我们不妨用线段树来维护这个过程. 但是貌似直接维护每个位置的值可能不太好维护. ...
- Educational Codeforces Round 35
Nearest Minimums 相同的数里最小的数里的最小距离 Solution Two Cakes Solution Three Garlands 瞎比试 Solution Inversion C ...
- How To Do Master Record Mass Maintenance
How To Do Master Record Mass Maintenance Which master records mass maintenance can be done? What do ...
- SAP事务码 一
SE80 -- edit source code. SE24 -- class create or display. SFP -- created and maintained independent ...
- 解析大型.NET ERP系统 十三种界面设计模式
成熟的ERP系统的界面应该都是从模板中拷贝出来的,各类功能的界面有规律可遵循.软件界面设计模式化或是艺术性的创作,我认可前者,模式化的界面客户容易举一反三,降低学习门槛.除了一些小部分的功能界面设计特 ...
- 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 ...
随机推荐
- 使用jmeter+ant进行接口自动化测试(数据驱动)之一:设计jmeter脚本
最近在做接口测试,因为公司有使用jmeter做接口测试的相关培训资料,所以还是先选择使用jmeter来批量管理接口,进行自动化测试.话不多说,进入正题: 1.使用csv文件保存接口测试用例,方便后期对 ...
- 集大1513 & 1514班 软件工程第一次作业评分与点评
谢谢大多数同学按时完成了作业,同学态度都比较端正,没有为了完成作业或者讨好老师而说一些假话空话. 很多同学选择CS之前并没有从兴趣或者擅长出发.这是一个普遍的现象,十年前我们是这样,十年后的孩子们还是 ...
- 设计模式NO.3
设计模式NO.3 本次博客内容为第三次设计模式的练习.根据老师的要求完成下列题目: 题目1 某商品管理系统的商品名称存储在一个字符串数组中,现需要自定义一个双向迭代器(MyIterator)实现对该商 ...
- Dijkstra算法课后补分博客
题目名称:Dijkstra算法 题目要求:课上给出相关附图,求解附图顶点A的单源最短路径. 附图: 做题过程 1.了解Dijkstra算法的相关知识,包括定义以及使用方法. 定义:Dijkstra算法 ...
- win7如何以管理员身份运行命令提示符(cmd)
1.进入到: C:\Windows\System32 2.找到cmd.exe文件 3.右键单击 ,选择 以管理员身份运行.
- Python 实现火车票查询工具
注意:由于 12306 的接口经常变化,课程内容可能很快过期,如果遇到接口问题,需要根据最新的接口对代码进行适当修改才可以完成实验. 一.实验简介 当你想查询一下火车票信息的时候,你还在上 12306 ...
- 201621123031 《Java程序设计》第2周学习总结
Week02-Java基本语法与类库 1. 本周学习总结 本周讲了Java的基本数据类型,主要分为八类(byte,short,int,long,double,float,char,boolean),其 ...
- 乐动力APP案例
第一部分 调研, 评测 下载软件并使用起来,描述最简单直观的个人第一次上手体验. 这款软件的主界面功能还是比较完善,里面有多个关于运动相关的数据,还有一些推荐健身教程,记录功能也十分不错,其中最难理解 ...
- lua保存table到文件并从文件解析成table
require("json") result = { ["ip"]="192.168.0.177", ["date"]= ...
- TortoiseGit安装与使用
公司的源码是在码云上,平时进行项目源码管理和团队开发都会使用到GIT,花了一天时间才将Git搞明白,这是一个工具,我在这里就简单说一下,其安装使用方法,也是对自己学习的总结;本文章适合于刚接触GIT的 ...