codeforce991G(线段树+思维)

maya!!!又FST。。。瞬间少了100ratingQAQ。。。明明都注意到有风险了干嘛还不管蛙qaqaqaqaq

好吧。。然后这题。。。又是啥思路都没。。然后又是在汪聚聚的点拨下我才想起上次不是才做过差不多的题嘛。。这么个做题法自己这么会有长进呢~~~

这题可以仿照上次的第一个思路,直接开个数据进行修改。。然后主要处理的是修改的最终结果,所以可以不用update。。。

这个细节比较灵活。。语文不好说不清楚。。看代码吧。。


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inf 1e9
#define eps 1e-8
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define NM 200005
#define nm 800005
#define pi 3.141592653
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}


int n,m,tot,_x,_y,_t,_v,a[NM];
struct info{
    int v[105],size;
}T[4*NM];

void pushdown(int i){
    if(T[i].size==1)return;
    inc(j,1,m){
        T[i<<1].v[j]=T[i].v[T[i<<1].v[j]];
        T[i<<1|1].v[j]=T[i].v[T[i<<1|1].v[j]];
    }
    inc(j,1,m)T[i].v[j]=j;
}

void build(int i,int x,int y){
    int t=x+y>>1;
    if(x==y){
        T[i].size=1;
        inc(j,1,m)T[i].v[j]=j;
        return;
    }
    pushdown(i);
    build(i<<1,x,t);build(i<<1|1,t+1,y);
    T[i].size=T[i<<1].size+T[i<<1|1].size;
}

void mod(int i,int x,int y){
    int t=x+y>>1;
    if(_y<x||y<_x)return;
    pushdown(i);
    if(_x<=x&&y<=_y){
        inc(j,1,m)if(T[i].v[j]==_t)T[i].v[j]=_v;
        return ;
    }
    mod(i<<1,x,t);mod(i<<1|1,t+1,y);
}
void out(int i,int x,int y){
    int t=x+y>>1;
    if(x==y){
        printf("%d ",T[i].v[a[x]]);
        return;
    }
    pushdown(i);
    out(i<<1,x,t);out(i<<1|1,t+1,y);
}

int main(){
  //  freopen("data.in","r",stdin);
    n=read();m=100;
    inc(i,1,n)a[i]=read();
    inc(i,1,m)T[1].v[i]=i;
    build(1,1,n);
    tot=read();
    while(tot--){
        //inc(i,1,m)printf("%d ",T[3].v[i]);putchar('\n');
        _x=read();_y=read();_t=read();_v=read();
        mod(1,1,n);
    }
    out(1,1,n);
    return 0;
}


G. Mass Change Queries
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are given an array a consisting of n integers. You have to process q queries to this array; each query is given as four numbers l, r, x and y, denoting that for every i such that l ≤ i ≤ r and ai = x you have to set ai equal to y.

Print the array after all queries are processed.

Input

The first line contains one integer n (1 ≤ n ≤ 200000) — the size of array a.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the elements of array a.

The third line contains one integer q (1 ≤ q ≤ 200000) — the number of queries you have to process.

Then q lines follow. i-th line contains four integers l, r, x and y denoting i-th query (1 ≤ l ≤ r ≤ n, 1 ≤ x, y ≤ 100).

Output

Print n integers — elements of array a after all changes are made.

Example
Input
5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5
Output
5 2 5 4 5 




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值