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 ...
随机推荐
- 实验三《Java面向对象程序设计》实验报告
20162308 实验三<Java面向对象程序设计>实验报告 实验内容 XP基础 XP核心实践 IDEA工具学习 密码学算法基础 实验步骤 (一)Refactor/Reformat使用 p ...
- 张旭升20162329 2006-2007-2 《Java程序设计》第一周学习总结
20162329 2006-2007-2 <Java程序设计>第一周学习总结 教材学习内容总结 通过打书上的代码熟悉了Java编程的基本过程 教材学习中的问题和解决过程 1.因为我的虚拟机 ...
- Digilent Xilinx USB Jtag cable
Digilent Xilinx USB Jtag cable 安装环境 操作系统:fedora 20 64bit 源链接:https://wiki.gentoo.org/wiki/Xilinx_USB ...
- IOS webview iframe 宽度超出屏幕解决方案
IOS 真机webview中,iframe 却不能很好地适应屏幕大小,总是超出屏幕尺寸,需要左右滚动才能看到完整页面. <div style="overflow: auto;-webk ...
- idea搭建springdata+mongodb+maven+springmvc
idea搭建springdata+mongodb+maven+springmvc 今天我们来学习一下SpringData操作MongoDB. 项目环境:IntelliJ IDEA2017+maven3 ...
- wireshark抓包分析tcp连接与断开
其实对于网络通信的学习,最好还是能够自己抓到包详细地一下,不然只单单通过文字和图的描述印象不够深刻.本文通过实际的抓包操作来看一下tcp的连接与断开是怎样的. 首先需要去https://www.wir ...
- html{font-size:62.5%}
为什么要使用html,body{font-size:62.5%}? 使用以下代码查看浏览器的初始font-size: <!DOCTYPE html><html><head ...
- 11-移动端开发教程-zepto.js入门教程
Zepto.js是一个轻量级的针对现代浏览器的JavaScript库, 它与jquery有着类似的api. 如果你会用jquery,那么你也会用zepto. 1. Why Zepto.js? API类 ...
- LeetCode & Q283-Move Zeroes-Easy
Array Two Pointers Description: Given an array nums, write a function to move all 0's to the end of ...
- Python内置函数(47)——vars
英文文档: vars([object]) Return the __dict__ attribute for a module, class, instance, or any other objec ...