[Explanations] fighting continued to attack as much as the country road L [P2129]

[Explanations] fighting continued to attack as much as the country road L [P2129]

Portal: \ (L \) fighting continued as much as the country road of attack \ ([P2129] \)

Description [title]

Given \ (n-\) coordinates, \ (m \) instruction, the instruction processing sequence should be back to front .

The final demand \ (n-\) coordinates.

[Enter]

The first line of two integers \ (n-, m \) .

Next \ (n-\) lines of two integers \ (x_i, y_i \) represents the \ (I \) coordinates.

Then \ (m \) lines of a first character \ (C \) ,

\ ((1). \) If \ (C \) is \ (\ text { 'm'} \) , then followed two integers \ (P, Q \) , requires all the coordinates \ ((x_i, y_i) \) becomes \ ((P + x_i, y_i + Q) \) .

\ (. (2) \) if \ (C \) is \ (\ {text 'X'} \) , put all coordinates from \ ((xi, yi) \ ) becomes \ ((- xi, yi ) \)

\ ((3). \) If \ (C \) is \ (\ text { 'Y'} \) , put all coordinates from \ ((xi, yi) \ ) becomes \ ((xi, -yi ) \) .

[Output]

[Sample]

样例输入:
3 3
0 0
4 -3
6 7
x
m -1 2
y

样例输出:
1 2
-3 5
-5 -5

【data range】

\(30 \%:\) \(1 \leqslant n,m \leqslant 1000\)

\(100 \%:\) \(1 \leqslant n,m \leqslant 5*10^5\)


【analysis】

Bigwigs are written matrix multiplication or analog , to me this is not your film matrix and konjac segment tree can only write a \ (\ text {QAQ} \) (seems to be the first to use this wonderful work method?).

Plus the interval, the interval multiplied by the template, but because it is monotonous inquiry, and there is no such Kichiku modulo operation, than [template] segment tree \ (2 \) and maintenance sequence is much simpler.

Maintain a multiplication mark \ (mul \) and the addition flag \ (add \) , direct update interval plus \ (add \) , multiplied by the interval \ (v \) to let \ (mul \) and \ (add \ ) are multiplied by \ (v \) .

Under the first pass pass mark \ (mul \) re-transmission \ (add \)

Other topics shining directly simulate it.

Pits: \ (m \) instruction to process backwards.

【Code】

#include<cstdio>
#define Re register int
#define pl (p<<1)//左儿子
#define pr (p<<1|1)//右儿子
#define mid (L+R>>1)
#define pa tr[p].add//加法标记
#define pm tr[p].mul//乘法标记
const int N=5e5+5;
int n,x,y,T,a[N],b[N];
inline void in(Re &x){
    Re f=0;x=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    x=f?-x:x;
}
struct Segment_Tree{
    struct QAQ{int l,r,ans,add,mul;}tr[N<<2];
    inline void updata_add(Re p,Re v){
        if(tr[p].l==tr[p].r)tr[p].ans+=v;//只需要更新叶子节点
        pa+=v;//但标记必须下传
    }
    inline void updata_mul(Re p,Re v){
        if(tr[p].l==tr[p].r)tr[p].ans*=v;//同上
        pm*=v,pa*=v;
    }
    inline void pushdown(Re p){//先下传乘法标记,再下传加法标记
        if(pm!=1)updata_mul(pl,pm),updata_mul(pr,pm),pm=1;//这里乘法标记也要初始化为1
        if(pa)updata_add(pl,pa),updata_add(pr,pa),pa=0;
    }
    inline void build(Re p,Re L,Re R){//初始化建树
        tr[p].l=L,tr[p].r=R,pm=1;//乘标记要初始化为1
        if(L==R){tr[p].ans=a[L];return;}
        build(pl,L,mid),build(pr,mid+1,R);
    }
    inline void change_add(Re p,Re l,Re r,Re v){//区间加
        Re L=tr[p].l,R=tr[p].r;
        if(l<=L&&R<=r){updata_add(p,v);return;}
        pushdown(p);
        if(l<=mid)change_add(pl,l,r,v);
        if(r>mid)change_add(pr,l,r,v);
    }
    inline void change_mul(Re p,Re l,Re r,Re v){//区间乘
        Re L=tr[p].l,R=tr[p].r;
        if(l<=L&&R<=r){updata_mul(p,v);return;}
        pushdown(p);
        if(l<=mid)change_mul(pl,l,r,v);
        if(r>mid)change_mul(pr,l,r,v);
    }
    inline int ask(Re p,Re w){//单点查询
        Re L=tr[p].l,R=tr[p].r;
        if(L==R)return tr[p].ans;
        pushdown(p);
        if(w<=mid)return ask(pl,w);
        else return ask(pr,w);
    }
}T1,T2;//T1:x坐标。T2:y坐标。
inline void sakura(Re T){
    Re x,y;char op;
    if(!T)return;
    scanf(" %c",&op);
    if(op=='m')in(x),in(y);
    sakura(T-1);
    if(op=='x')T1.change_mul(1,1,n,-1);//(x,y) -> (-x,y)
    else if(op=='y')T2.change_mul(1,1,n,-1);//(x,y) ->(x,-y)
    else T1.change_add(1,1,n,x),T2.change_add(1,1,n,y);//(x,y) -> (x+p,y+q)
}
int main(){
    // freopen("123.txt","r",stdin);
    in(n),in(T);
    for(Re i=1;i<=n;++i)in(a[i]),in(b[i]);
    T1.build(1,1,n);//第一棵树
    for(Re i=1;i<=n;++i)a[i]=b[i];
    T2.build(1,1,n);//第二课树
    sakura(T);
    for(Re i=1;i<=n;++i)printf("%d %d\n",T1.ask(1,i),T2.ask(1,i));
}

Guess you like

Origin www.cnblogs.com/Xing-Ling/p/11571500.html