比赛 Asm.Def战记之圣地亚哥“杯2015 评测结果 AAAAAAAWWW
题目名称 Asm.Def的命令 最终得分 70
用户昵称 HYOI_ingn 运行时间 4.782 s
代码语言 C++ 内存使用 41.13 MiB
提交时间 2019-10-23 18:22:59
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
typedef pair<double,double> PDD;
const int maxn=2e5+10;
const double pi=acos(-1.0);
int read(){
    int x=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*w;
}
double tag1[maxn<<2],tag2[maxn<<2];
int tag3[maxn<<2];//1 add 3 rotate
double wsp1[maxn<<2],wsp2[maxn<<2];
int n,q;
void build(int rt,int l,int r){
    wsp1[rt]=0,wsp2[rt]=0;
    if(l==r){wsp2[rt]=l;return;}
    int mid=(l+r)>>1;
    build(rt<<1,l,mid);
    build(rt<<1|1,mid+1,r);
}
void color1(int rt,double dx,double dy){
    wsp1[rt]+=dx;wsp2[rt]+=dy;
    tag1[rt]+=dx;tag2[rt]+=dy;
}
void color2(int rt,int deg){
    tag3[rt]=(tag3[rt]+deg)%360;
    double r=sqrt(tag1[rt]*tag1[rt]+tag2[rt]*tag2[rt]);
    double alpha,beta,theta=deg*pi/(double)180;
    if(r!=0){
        alpha=acos(tag1[rt]/r);
        beta=acos(cos(alpha)*cos(theta)-sin(alpha)*sin(theta));
        tag1[rt]=r*cos(beta),tag2[rt]=r*sin(beta);
    }
    r=sqrt(wsp1[rt]*wsp1[rt]+wsp2[rt]*wsp2[rt]);
    if(r!=0){
        alpha=acos(wsp1[rt]/r);
        beta=acos(cos(alpha)*cos(theta)-sin(alpha)*sin(theta));
        wsp1[rt]=r*cos(beta),wsp2[rt]=r*sin(beta);
    }
}
void push_color(int rt){
    if(tag3[rt]){
        color2(rt<<1,tag3[rt]);
        color2(rt<<1|1,tag3[rt]);
        tag3[rt]=0;
    }
    color1(rt<<1,tag1[rt],tag2[rt]);
    color1(rt<<1|1,tag1[rt],tag2[rt]);
    tag1[rt]=tag2[rt]=0;
}
void modify1(int rt,int l,int r,int nowl,int nowr,double dx,double dy){
    push_color(rt);
    if(nowl<=l&&nowr>=r){
        color1(rt,dx,dy);
        return;
    }
    int mid=(l+r)>>1;
    if(nowl<=mid)modify1(rt<<1,l,mid,nowl,nowr,dx,dy);
    if(nowr>mid)modify1(rt<<1|1,mid+1,r,nowl,nowr,dx,dy);
}
void modify2(int rt,int l,int r,int nowl,int nowr,int deg){
    push_color(rt);
    if(nowl<=l&&nowr>=r){
        color2(rt,deg);
        return; 
    }
    int mid=(l+r)>>1;
    if(nowl<=mid)modify2(rt<<1,l,mid,nowl,nowr,deg);
    if(nowr>mid)modify2(rt<<1|1,mid+1,r,nowl,nowr,deg);
}
PDD query(int rt,int l,int r,int pos){
    if(l==r){
        return PDD{wsp1[rt],wsp2[rt]};
    }
    push_color(rt);
    int mid=(l+r)>>1;
    if(pos<=mid)return query(rt<<1,l,mid,pos);
    else return query(rt<<1|1,mid+1,r,pos);
}
int main(){
    freopen("asm_command.in","r",stdin);
    freopen("asm_command.out","w",stdout);
    n=read(),q=read();
    build(1,1,n);
    while(q--){
        int opt=read();
        if(opt==0){
            int x=read();
            PDD pg=query(1,1,n,x);
            cout<<fixed<<setprecision(1)<<pg.first<<" "<<pg.second<<"\n";
        }
        else if(opt==1){
            int l=read(),r=read(),dx=read(),dy=read();
            modify1(1,1,n,l,r,dx,dy);
        }
        else{
            int l=read(),r=read(),pp=read()%360;
            modify2(1,1,n,l,r,pp);
        }
    }
}