結果

問題 No.1226 I hate Robot Arms
ユーザー chielochielo
提出日時 2020-09-11 23:18:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 3,760 bytes
コンパイル時間 2,455 ms
コンパイル使用メモリ 203,384 KB
実行使用メモリ 19,092 KB
最終ジャッジ日時 2023-08-30 10:27:32
合計ジャッジ時間 11,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
18,064 KB
testcase_01 AC 7 ms
18,216 KB
testcase_02 AC 53 ms
18,276 KB
testcase_03 AC 59 ms
18,404 KB
testcase_04 AC 64 ms
18,740 KB
testcase_05 AC 58 ms
19,092 KB
testcase_06 AC 147 ms
18,720 KB
testcase_07 AC 50 ms
18,456 KB
testcase_08 AC 19 ms
18,876 KB
testcase_09 AC 105 ms
18,248 KB
testcase_10 AC 19 ms
18,204 KB
testcase_11 AC 72 ms
18,544 KB
testcase_12 AC 42 ms
18,568 KB
testcase_13 AC 32 ms
18,952 KB
testcase_14 AC 123 ms
18,144 KB
testcase_15 AC 13 ms
18,744 KB
testcase_16 AC 142 ms
18,776 KB
testcase_17 AC 43 ms
18,220 KB
testcase_18 AC 32 ms
18,520 KB
testcase_19 AC 76 ms
18,720 KB
testcase_20 AC 69 ms
18,704 KB
testcase_21 AC 92 ms
18,672 KB
testcase_22 AC 149 ms
18,924 KB
testcase_23 AC 157 ms
18,968 KB
testcase_24 AC 151 ms
18,720 KB
testcase_25 AC 155 ms
19,060 KB
testcase_26 AC 149 ms
18,796 KB
testcase_27 AC 167 ms
18,908 KB
testcase_28 AC 165 ms
18,904 KB
testcase_29 AC 164 ms
18,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

const int maxn = 1e5 + 3, lo = 0x2'0000;
const double pi = acos(-1);

struct SEG {
    struct node {
        double a[2][2], b[2];
        bool m;
        void tag(double u[2][2], double v[2]) {
            double c[2][2];
            for(int i = 0; i < 2; ++i) {
                for(int j = 0; j < 2; ++j) {
                    c[i][j] = 0.0;
                    for(int k = 0; k < 2; ++k) {
                        c[i][j] += a[i][k] * u[k][j];
                    }
                }
            }
            memcpy(a, c, sizeof(a));
            double d[2];
            for(int i = 0; i < 2; ++i) {
                d[i] = 0;
                for(int k = 0; k < 2; ++k)
                    d[i] += b[k] * u[k][i];
                d[i] += v[i];
            }
            memcpy(b, d, sizeof(b));
            m = true;
        }
        void down(node &u, node &v) {
            if(m) {
                u.tag(a, b);
                v.tag(a, b);
                *this = {{{1.0, 0.0}, {0.0, 1.0}}, {0.0, 0.0}, false};
            }
        }
    } seg[lo * 2];
    void init() {
        for(int i = 0; i < lo * 2; ++i) {
            seg[i] = {{{1.0, 0.0}, {0.0, 1.0}}, {0.0, 0.0}, false};
        }
    }
    void modify(int l, int r, double u[2][2], double v[2]) {
        down(l - 1); down(r);
        for(int i = l + lo, j = r + lo; i < j; i /= 2, j /= 2) {
            if(i & 1) {
                seg[i++].tag(u, v);
            }
            if(j & 1) {
                seg[j++].tag(u, v);
            }
        }
    }
    void down(int k) {
        if(k < 0 || k >= lo)
            return;
        for(int i = 1, j = lo; i < lo; j /= 2, i = i * 2 + bool(k & j)) {
            seg[i].down(seg[i * 2], seg[i * 2 + 1]);
        }
    }
    std::pair<double, double> query(int k, double v[2]) {
        down(k);
        double d[2];
        auto &&u = seg[k + lo];
        for(int i = 0; i < 2; ++i) {
            d[i] = 0;
            for(int j = 0; j < 2; ++j)
                d[i] += v[j] * u.a[j][i];
            d[i] += u.b[i];
        }
        return {d[0], d[1]};
    }
} s;

std::pair<double, double> get(int i) {
    double v[2] = {double(i), 0.0};
    return s.query(i, v);
}

int ct[maxn], cl[maxn];

void rotate(int k, int v) {
    double t = double(v) / 360. * 2. * pi;
    auto uu = get(k - 1);
    SEG::node p = {{{1.0, 0.0}, {0.0, 1.0}}, {0.0, 0.0}, false};
    {
        double u[2][2] = {{1.0, 0.0}, {0.0, 1.0}};
        double w[2] = {-uu.first, -uu.second};
        p.tag(u, w);
    }
    {
        double u[2][2] = {{cos(t), sin(t)}, {-sin(t), cos(t)}};
        double w[2] = {0.0, 0.0};
        p.tag(u, w);
    }
    {
        double u[2][2] = {{1.0, 0.0}, {0.0, 1.0}};
        double w[2] = {+uu.first, +uu.second};
        p.tag(u, w);
    }
    s.modify(k, lo, p.a, p.b);
}

void extend(int k, int v) {
    auto uu = get(k - 1);
    auto vv = get(k);
    double dx = vv.first - uu.first;
    double dy = vv.second - uu.second;
    double uvl = sqrt(dx * dx + dy * dy);
    {
        double u[2][2] = {{1.0, 0.0}, {0.0, 1.0}};
        double w[2] = {dx / uvl * v, dy / uvl * v};
        s.modify(k, lo, u, w);
    }
}

int main() {
    s.init();
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i) {
        ct[i] = 0;
        cl[i] = 1;
    }
    for(int i = 0; i < q; ++i) {
        int op, k, v;
        scanf("%d%d", &op, &k);
        if(op == 0) {
            scanf("%d", &v);
            rotate(k, v - ct[k]);
            ct[k] = v;
        } else if(op == 1) {
            scanf("%d", &v);
            extend(k, v - cl[k]);
            cl[k] = v;
        } else {
            auto p = get(k);
            printf("%.6f %.6f\n", p.first, p.second);
        }
    }
    return 0;
}
0