比赛 Asm.Def战记之圣地亚哥“杯2015 评测结果 AAAAAAAWAA
题目名称 Asm.Def的命令 最终得分 90
用户昵称 rainy 运行时间 7.473 s
代码语言 C++ 内存使用 44.27 MiB
提交时间 2019-10-23 18:21:39
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
typedef long long int_t;
char getch(){ static char buf[100000],*s1,*s2; return (s1 == s2) && (s2 = (s1 = buf) + fread(buf,1,100000,stdin)),s1 == s2 ? EOF : *s1++; }

#ifdef local
#define getch getchar
#endif

int_t read(){
    int_t x = 0, w = 1;char ch = 0;
    while(!isdigit(ch)) {ch = getch(); if(ch == '-') w = -1;}
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getch();
    return x * w;
}

// templates above

const int_t maxn = 100010;
const double pi = acos(-1);

double j2h(double deg){ return deg * pi / 180; }
double h2j(double deg){ return deg * 180 / pi; }

struct Vec{
    double len, deg;
    Vec(){len = deg = 0;}
    Vec(double x,double y){
        len = sqrt(x*x + y*y);
        deg = acos(x / len);
        deg = h2j(deg); 
        if(y < 0) deg = 360 - deg;
        while(this -> deg > 360) this -> deg -= 360;
        while(this -> deg < 0) this -> deg += 360;
        if(x <= 1e-7 && x >= 1e-7) deg = (y > 0) ? 90 : 270;
    }
    void operator +=(Vec b){
        if(b.len == 0) return;
        if(this -> len == 0) *this = b;
        else *this = Vec(cos(j2h(deg)) * len + cos(j2h(b.deg)) * b.len,sin(j2h(deg)) * len + sin(j2h(b.deg)) * b.len);
    }
    void operator *=(int_t deg){
        this -> deg += deg;
        while(this -> deg > 360) this -> deg -= 360;
        while(this -> deg < 0) this -> deg += 360;
    }
};

Vec seg[maxn << 3],tag[maxn << 3];int_t dTag[maxn << 3];

#define lson rt << 1
#define rson lson | 1

void pushdown(int_t rt,int_t l,int_t r){
    dTag[lson] = (dTag[lson] + dTag[rt]) % 360; 
    dTag[rson] = (dTag[rson] + dTag[rt]) % 360;
    tag[lson] *= dTag[rt]; tag[rson] *= dTag[rt];
    seg[lson] *= dTag[rt]; seg[rson] *= dTag[rt];
    tag[lson] += tag[rt]; tag[rson] += tag[rt];
    seg[lson] += tag[rt]; seg[rson] += tag[rt];
    tag[rt] = Vec(); dTag[rt] = 0;
}

void modify1(int_t rt,int_t l,int_t r,int_t x,int_t y,Vec v){
    pushdown(rt,l,r);
    if(x <= l && r <= y) {seg[rt] += v; tag[rt] += v; return;}
    int_t mid = (l + r) >> 1;
    if(mid >= x) modify1(lson,l,mid,x,y,v);
    if(mid < y) modify1(rson,mid+1,r,x,y,v);
}

void modify2(int_t rt,int_t l,int_t r,int_t x,int_t y,int_t v){
    pushdown(rt,l,r);
    if(x <= l && r <= y) {seg[rt] *= v; dTag[rt] += v; return;}
    int_t mid = (l + r) >> 1;
    if(mid >= x) modify2(lson,l,mid,x,y,v);
    if(mid < y) modify2(rson,mid+1,r,x,y,v);
}

Vec query(int_t rt,int_t l,int_t r,int_t pos){
    pushdown(rt,l,r);
    if(l == r) return seg[rt];
    int_t mid = (l + r) >> 1;
    if(mid >= pos) return query(lson,l,mid,pos);
    return query(rson,mid+1,r,pos);
}

int main(){
    freopen("asm_command.in","r",stdin);
    freopen("asm_command.out","w",stdout);
    int_t n = read(),q = read();
    for(int_t i=1;i<=n;i++) modify1(1,1,n,i,i,Vec(0,i));
    while(q--){
        int_t opt = read();
        if(opt == 0){
            int_t pos = read();
            Vec ans = query(1,1,n,pos);
            printf("%.1lf %.1lf\n",ans.len * cos(j2h(ans.deg)),ans.len * sin(j2h(ans.deg)));
        }else if(opt == 1){
            int_t a = read(),b = read(),dx = read(),dy = read();
            modify1(1,1,n,a,b,Vec(dx,dy));
        }else{
            int_t a = read(),b = read(), deg = read();
            modify2(1,1,n,a,b,deg);
        }
    }
}