链接

大意: 给定序列, 每次操作将区间[l,r]中的x全改为y, 最后输出序列

权值范围比较小, 对每个权值开一颗线段树, 每次将x合并到y上即可

#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define mid (l+r>>1)
#define lc (o<<1)
#define rc (lc|1) using namespace std;
typedef long long ll; const int N = 2e5+10;
int a[N], n, m, t;
int rt[110], tot, ql, qr, now;
struct _ {int l,r;}v[N<<5]; void ins(int &o, int l, int r, int pos) {
if (!o) o=++tot;
if (l==r) return;
if (mid>=pos) ins(v[o].l,l,mid,pos);
else ins(v[o].r,mid+1,r,pos);
} int merge(int x, int y) {
if (!x||!y) return x^y;
v[x].l = merge(v[x].l,v[y].l);
v[x].r = merge(v[x].r,v[y].r);
return x;
} void update(int &x, int &y, int l, int r) {
if (!x) return;
if (ql<=l&&r<=qr) return y=merge(x,y),void(x=0);
if (!y) y=++tot;
if (mid>=ql) update(v[x].l,v[y].l,l,mid);
if (mid<qr) update(v[x].r,v[y].r,mid+1,r);
} void dfs(int o, int l, int r) {
if (!o) return;
if (l==r) return void(a[l]=now);
dfs(v[o].l,l,mid),dfs(v[o].r,mid+1,r);
} int main() {
scanf("%d", &n);
REP(i,1,n) {
int t;
scanf("%d", &t);
ins(rt[t],1,n,i);
}
scanf("%d", &m);
while (m--) {
int x, y;
scanf("%d%d%d%d", &ql, &qr, &x, &y);
if (x!=y) update(rt[x],rt[y],1,n);
}
REP(i,1,100) now=i,dfs(rt[i],1,n);
REP(i,1,n) printf("%d ",a[i]);
puts("");
}

Mass Change Queries CodeForces - 911G (线段树合并)的更多相关文章

  1. Mass Change Queries Codeforces - 911G

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

  2. Alyona and a tree CodeForces - 739B (线段树合并)

    大意: 给定有根树, 每个点$x$有权值$a_x$, 对于每个点$x$, 求出$x$子树内所有点$y$, 需要满足$dist(x,y)<=a_y$. 刚开始想错了, 直接打线段树合并了..... ...

  3. Recursive Queries CodeForces - 1117G (线段树)

    题面: 刚开始想复杂了, 还以为是个笛卡尔树.... 实际上我们发现, 对于询问(l,r)每个点的贡献是$min(r,R[i])-max(l,L[i])+1$ 数据范围比较大在线树套树的话明显过不了, ...

  4. codeforces 893F - Physical Education Lessons 动态开点线段树合并

    https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的 ...

  5. Codeforces 671D Roads in Yusland [树形DP,线段树合并]

    洛谷 Codeforces 这是一个非正解,被正解暴踩,但它还是过了. 思路 首先很容易想到DP. 设\(dp_{x,i}\)表示\(x\)子树全部被覆盖,而且向上恰好延伸到\(dep=i\)的位置, ...

  6. Codeforces 666E Forensic Examination SAM or SA+线段树合并

    E. Forensic Examination http://codeforces.com/problemset/problem/666/E 题目大意:给模式串S以及m个特殊串,q个询问,询问S的子串 ...

  7. [Codeforces 266E]More Queries to Array...(线段树+二项式定理)

    [Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...

  8. codeforces 600E E. Lomsat gelral (线段树合并)

    codeforces 600E E. Lomsat gelral 传送门:https://codeforces.com/contest/600/problem/E 题意: 给你一颗n个节点的树,树上的 ...

  9. 【Codeforces 1037H】Security(SAM & 线段树合并)

    Description 给出一个字符串 \(S\). 给出 \(Q\) 个操作,给出 \(L, R, T\),求字典序最小的 \(S_1\),使得 \(S^\prime\) 为\(S[L..R]\) ...

随机推荐

  1. Vue源码解析之nextTick

    Vue源码解析之nextTick 前言 nextTick是Vue的一个核心功能,在Vue内部实现中也经常用到nextTick.但是,很多新手不理解nextTick的原理,甚至不清楚nextTick的作 ...

  2. Kotlin语言Web库又添一虎将:Kweb

    Kweb是一个库,您可以利用它使用Kotlin编程语言轻松构建Web应用程序.从程序员的角度来看,它基本上消除了浏览器和服务器之间的分离.这意味着只操纵DOM的事件不需要进行服务器往返.由于Kweb是 ...

  3. Windows下MongoDB安装

    1.解压mongodb-win32-i386-1.8.1.zip ,创建路径d:\mongodb ,将解压后的Bin文件Copy to 此文件夹下 2.d:\mongodb 下建立Data文件夹 d: ...

  4. JSP输出HTML时产生的大量空格和换行的去除方法

    在WEB应用中,如果使用jsp作为view层的显示模板,都会被空格/空换行问题所困扰.     这个问题当年也困扰了我比较长的时间.因为在jsp内使用的EL标签和其他标签时,会产生大量的空格和换行符. ...

  5. C Looooops(扩展欧几里得)题解

    A Compiler Mystery: We are given a C-language style for loop of type  for (variable = A; variable != ...

  6. TeeChart的网络资料

    TeeChart坐标轴常见问题 http://www.shaoqun.com/a/54063.aspx TeeChart常用编程语句汇总(C#) http://www.ev get.com/artic ...

  7. 51nod 1070 Bash游戏 V4

    这种博弈题  都是打表找规律 可我连怎么打表都不会 这个是凑任务的吧....以后等脑子好些了 再琢磨吧 就是斐波那契数列中的数 是必败态 #include<bits/stdc++.h> u ...

  8. Intellij新建Spring项目引入用户目录下的Spring jar包

    首先,在IntelliJ IDEA中新建module,选择Spring应用:   在初次使用时,如果IDE检测到本地没有spring核心库,则会在新建过程中下载对应库文件,在使用spring框架时,可 ...

  9. ovs-ofctl: s1 is not a bridge or a socket 解决方法

    参考: ovs-vsctl: Error detected while setting up bridge ovs-ofctl: s1 is not a bridge or a socket 解决方法 ...

  10. workerman如何写mysql连接池

    首先要了解为什么用连接池,连接池能为你解决什么问题 连接池主要的作用1.减少与数据服务器建立TCP连接三次握手及连接关闭四次挥手的开销,从而降低客户端和mysql服务端的负载,缩短请求响应时间2.减少 ...