# [cf911g] Mass Change Queries

Source: Internet
Author: User

The main topic: Give a series \$s (s_i\leqslant100) \$, there are \$q\$ operations, each operation is to change the interval \$[l,r]\$ equals \$x\$ number to \$y\$, output answer

Puzzle : line tree, each node to save the interval of each value will become what, and finally sweep it all over.

card point: None

C + + Code:

`#include <cstdio> #define MAXN 200001int S[MAXN], ans[maxn];namespace SgT {int n;struct node {int s[100];inline node Init () {for (register int i = 0; i < i++) s[i] = i;} inline void Modify (int x, int y) {for (register int i = 0; i <; i++) if (s[i] = = x) s[i] = y;} inline int getnum (int x) {return s[x-1] + 1;} Inline node operator * (const node &AMP;RHS) const {node res;for (register int i = 0; i <; i++) Res.s[i] = rhs.s[s[ I]];return res;}} V[MAXN << 2];void Build (int rt, int l, int r) {v[rt].init (), if (L = = r) return; int mid = L + R >> 1;build (RT << 1, L, mid); build (rt << 1 | 1, mid + 1, r);} inline void pushdown (int rt) {V[rt << 1] = v[rt << 1] * V[RT]; V[rt << 1 | 1] = V[RT << 1 | 1] * V[RT]; V[rt].init ();} int L, R, X, y;void modify (int rt, int L, int R) {if (L <= l && R >= R) {v[rt].modify (x, y); return;} int mid = L + R >> 1;pushdown (RT), if (L <= mid) modify (RT << 1, L, mid); if (R &GT MID) Modify (RT << 1 | 1, mid + 1, r);} void Add (int ll, int rr, int xx, int yy) {L = ll, R = RR, x = xx-1, y = yy-1;modify (1, 1, n);} void get (int rt, int l, int r) {if (L = = r) {Ans[l] = V[rt].getnum (S[l]); return;} Pushdown (RT); int mid = L + R >> 1;get (RT << 1, L, mid); get (rt << 1 | 1, mid + 1, r);}} Using Sgt::add;int N, q;int Main () {scanf ("%d", &n); Sgt::n = n;for (int i = 1; I <= n; i++) scanf ("%d", S + i); Sgt::build (1, 1, n); scanf ("%d", &q); for (int i = 1, L, R, X, y; i <= q; i++) {scanf ("%d%d%d%d", &l, &r, &am P;x, &y); Add (L, r, X, y);} Sgt::get (1, 1, n); for (int i = 1; I <= n; i++) {printf ("%d", Ans[i]);p Utchar (i = = n?) ' \ n ': ');} return 0;}`

[cf911g] Mass Change Queries

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.