Jys

#pragma GCC optimize("Ofast")
#pragma GCC target("sse2")
#include <bits/stdc++.h>
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define mid (l + r >> 1)

using namespace std;
const int U = 100, N = 200000;


int tr[(N << 2) + 5][U + 5];
int n, a, b, x, y;
int w[N + 5];


void Build(int p, int l, int r)
{
    for (int i = 1; i <= U; i++) tr[p][i] = i;
    if (l == r) return;
    Build(ls(p), l, mid), Build(rs(p), mid + 1, r);
}


void Psd(int p, int l, int r)
{
    if (l == r) return;
    for (int i = 1; i <= U; i++)
        tr[ls(p)][i] = tr[p][tr[ls(p)][i]],
        tr[rs(p)][i] = tr[p][tr[rs(p)][i]];
    for (int i = 1; i <= U; i++) tr[p][i] = i;
}


void Modify(int p, int l, int r)
{
    if (l >= a && r <= b) 
    {
        for (int i = 1; i <= U; i++) if (tr[p][i] == x) tr[p][i] = y;
        return;
    }
    Psd(p, l, r);
    if (a <= mid) Modify(ls(p), l, mid);
    if (b > mid) Modify(rs(p), mid + 1, r);
}


void Print(int p, int l, int r)
{
    if (l == r) return (void)printf("%d ", tr[p][w[l]]);
    Psd(p, l, r), Print(ls(p), l, mid), Print(rs(p), mid + 1, r);
}


int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
    Build(1, 1, n);
    int q;
    for (scanf("%d", &q); q--;) scanf("%d%d%d%d", &a, &b, &x, &y), Modify(1, 1, n);
    return Print(1, 1, n), 0;
}

 

posted @ 2020-05-08 14:09  Oply  阅读(255)  评论(0编辑  收藏  举报