結果

問題 No.1226 I hate Robot Arms
ユーザー MisterMister
提出日時 2020-09-11 22:01:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,327 ms / 2,000 ms
コード長 3,812 bytes
コンパイル時間 1,359 ms
コンパイル使用メモリ 119,180 KB
実行使用メモリ 15,620 KB
最終ジャッジ日時 2023-10-06 09:35:18
合計ジャッジ時間 35,241 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 367 ms
4,620 KB
testcase_03 AC 448 ms
6,204 KB
testcase_04 AC 652 ms
15,304 KB
testcase_05 AC 673 ms
15,440 KB
testcase_06 AC 1,282 ms
15,620 KB
testcase_07 AC 339 ms
4,696 KB
testcase_08 AC 344 ms
15,316 KB
testcase_09 AC 787 ms
6,212 KB
testcase_10 AC 96 ms
4,380 KB
testcase_11 AC 699 ms
15,440 KB
testcase_12 AC 368 ms
9,248 KB
testcase_13 AC 491 ms
15,316 KB
testcase_14 AC 949 ms
6,276 KB
testcase_15 AC 332 ms
15,360 KB
testcase_16 AC 1,286 ms
15,304 KB
testcase_17 AC 347 ms
6,136 KB
testcase_18 AC 261 ms
6,140 KB
testcase_19 AC 740 ms
15,316 KB
testcase_20 AC 675 ms
15,368 KB
testcase_21 AC 836 ms
15,304 KB
testcase_22 AC 1,324 ms
15,444 KB
testcase_23 AC 1,326 ms
15,368 KB
testcase_24 AC 1,327 ms
15,316 KB
testcase_25 AC 1,327 ms
15,328 KB
testcase_26 AC 1,325 ms
15,444 KB
testcase_27 AC 1,304 ms
15,620 KB
testcase_28 AC 1,303 ms
15,372 KB
testcase_29 AC 1,303 ms
15,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <tuple>
#include <functional>

template <class T>
struct SegmentTree {
    using Merger = std::function<T(T, T)>;

    int length;
    std::vector<T> dat;
    T unit;
    Merger merge;

    SegmentTree() = default;

    SegmentTree(int n, const T& unit, const Merger& merge)
        : length(1), unit(unit), merge(merge) {
        while (length < n) length <<= 1;
        dat.assign(length * 2, unit);
    }

    template <class Container>
    SegmentTree(const Container& elems, const T& unit, const Merger& merge)
        : length(1), unit(unit), merge(merge) {
        int n = elems.size();
        while (length < n) length <<= 1;

        dat.assign(length * 2, unit);

        std::copy(elems.begin(), elems.end(), dat.begin() + length);

        for (int nidx = length - 1; nidx >= 1; --nidx) {
            T vl = dat[nidx * 2 + 0];
            T vr = dat[nidx * 2 + 1];
            dat[nidx] = merge(vl, vr);
        }
    }

    void update(int nidx, const T& elem) {
        nidx += length;
        dat[nidx] = elem;

        while (nidx > 0) {
            nidx >>= 1;
            T vl = dat[nidx * 2 + 0];
            T vr = dat[nidx * 2 + 1];
            dat[nidx] = merge(vl, vr);
        }
    }

    T fold(int ql, int qr) const {
        ql = std::max(ql, 0);
        qr = std::min(qr, length);
        ql += length, qr += length;

        T lacc = unit, racc = unit;
        while (ql < qr) {
            if (ql & 1) {
                lacc = merge(lacc, dat[ql]);
                ++ql;
            }
            if (qr & 1) {
                --qr;
                racc = merge(dat[qr], racc);
            }
            ql >>= 1, qr >>= 1;
        }

        return merge(lacc, racc);
    }

    T get(int idx) const { return dat[idx + length]; }
    T fold_all() const { return dat[1]; }
};

using ldouble = long double;
const ldouble PI = std::acos(-1.L);

void solve() {
    int n;
    std::cin >> n;

    SegmentTree<std::tuple<ldouble, ldouble, ldouble>>
        seg(n, std::make_tuple(0, 0, 0),
            [](auto a, auto b) {
                auto [al, at, ap] = a;
                auto [bl, bt, bp] = b;

                auto x = al * std::cos(at + ap) + bl * std::cos(ap + bt + bp),
                     y = al * std::sin(at + ap) + bl * std::sin(ap + bt + bp);
                return std::make_tuple(std::hypot(x, y),
                                       std::atan2(y, x) - (ap + bp),
                                       ap + bp);
            });
    for (int i = 0; i < n; ++i) seg.update(i, std::make_tuple(1, 0, 0));

    int q;
    std::cin >> q;
    while (q--) {
        int c;
        std::cin >> c;

        switch (c) {
            case 0: {
                int i;
                ldouble p;
                std::cin >> i >> p;
                --i;
                p *= PI / 180;

                auto [sl, st, sp] = seg.get(i);
                seg.update(i, std::make_tuple(sl, st, p));
                break;
            }

            case 1: {
                int i;
                ldouble l;
                std::cin >> i >> l;
                --i;

                auto [sl, st, sp] = seg.get(i);
                seg.update(i, std::make_tuple(l, st, sp));
                break;
            }

            case 2: {
                int i;
                std::cin >> i;

                auto [l, t, p] = seg.fold(0, i);
                std::cout << l * std::cos(t + p) << " " << l * std::sin(t + p) << "\n";
                break;
            }
        }
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cout << std::fixed << std::setprecision(10);
    std::cerr << std::fixed << std::setprecision(10);

    solve();

    return 0;
}
0