結果

問題 No.1226 I hate Robot Arms
ユーザー YamaKasaYamaKasa
提出日時 2020-09-15 03:45:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 2,314 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 172,312 KB
実行使用メモリ 12,176 KB
最終ジャッジ日時 2023-09-04 01:29:03
合計ジャッジ時間 9,992 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 71 ms
4,748 KB
testcase_03 AC 80 ms
5,612 KB
testcase_04 AC 88 ms
10,628 KB
testcase_05 AC 77 ms
10,892 KB
testcase_06 AC 205 ms
11,816 KB
testcase_07 AC 64 ms
4,812 KB
testcase_08 AC 22 ms
10,344 KB
testcase_09 AC 150 ms
6,012 KB
testcase_10 AC 18 ms
4,380 KB
testcase_11 AC 100 ms
10,668 KB
testcase_12 AC 55 ms
7,328 KB
testcase_13 AC 40 ms
10,540 KB
testcase_14 AC 181 ms
5,972 KB
testcase_15 AC 15 ms
10,300 KB
testcase_16 AC 203 ms
11,248 KB
testcase_17 AC 57 ms
5,664 KB
testcase_18 AC 37 ms
5,460 KB
testcase_19 AC 102 ms
10,728 KB
testcase_20 AC 93 ms
10,828 KB
testcase_21 AC 129 ms
10,864 KB
testcase_22 AC 215 ms
11,936 KB
testcase_23 AC 209 ms
11,856 KB
testcase_24 AC 213 ms
11,936 KB
testcase_25 AC 210 ms
12,176 KB
testcase_26 AC 211 ms
11,904 KB
testcase_27 AC 243 ms
12,000 KB
testcase_28 AC 238 ms
11,892 KB
testcase_29 AC 240 ms
11,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

double R = acos(-1) / 180;
struct Node {
    double x, y, t;
    Node(double x, double y, double t) : x(x), y(y), t(t){}
};

class SegmentTree {
private:
    int n;
    vector<Node> node;

public:
    SegmentTree(int N) {
        n = 1;
        while (n < N) n *= 2;
        node.resize(2 * n - 1, Node(0, 0, 0));
        for (int i = 1; i < N; i++) {
            node[i + n - 1].x = 1;
        }
        for (int i = n - 2; i >= 0; i--) {
            node[i] = add(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    Node update(double t, double d) {
        return Node(d * cos(R * t), d * sin(R * t), t);
    }

    Node add(Node v1, Node v2) {
        double x = v1.x + v2.x * cos(R * v1.t) - v2.y * sin(R * v1.t);
        double y = v1.y + v2.x * sin(R * v1.t) + v2.y * cos(R * v1.t);
        return Node(x, y, v1.t + v2.t);
    }

    void update_all(int i, double t, double d) {
        i += n - 1;
        node[i] = update(t, d);
        
        while (i > 0) {
            i = (i - 1) / 2;
            node[i] = add(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    Node query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return Node(0, 0, 0);        
        if (a <= l && r <= b) return node[k];

        Node v_l = query(a, b, 2 * k + 1, l, (l + r) / 2);
        Node v_r = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return add(v_l, v_r);
    }

    void disp() {
        int idx = 0;
        for (Node i : node) {
            printf("%d ( %f %f %f)\n",idx, i.x, i.y, i.t);
            idx++;
        }
    }

};


int main() {
    int N, Q;
    int a, b, x;
    cin >> N >> Q;
    vector<Node> ans;
    SegmentTree st(N + 1);

    int t[N]{}, d[N]{};
    fill(d, d + N, 1);
    for (int i = 0; i < Q; i++) {
        cin >> a >> b;
        if (a == 2) {
            Node p = st.query(0, b + 1);
            ans.push_back(p);
        } else {
            cin >> x;
            if (a == 0) {
                t[b - 1] = x;
            } else {
                d[b - 1] = x;
            }
            st.update_all(b, t[b - 1], d[b - 1]);
        }
    }
    for (Node p : ans) {
        printf("%.9f %.9f\n", p.x, p.y);
    }
    //st.disp();
    return 0;
}
0