結果

問題 No.1226 I hate Robot Arms
ユーザー YamaKasaYamaKasa
提出日時 2020-09-15 15:57:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 2,325 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 173,356 KB
実行使用メモリ 12,168 KB
最終ジャッジ日時 2023-09-04 01:48:57
合計ジャッジ時間 8,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 70 ms
4,952 KB
testcase_03 AC 79 ms
5,624 KB
testcase_04 AC 84 ms
10,632 KB
testcase_05 AC 74 ms
10,856 KB
testcase_06 AC 196 ms
12,028 KB
testcase_07 AC 64 ms
4,860 KB
testcase_08 AC 22 ms
10,356 KB
testcase_09 AC 147 ms
6,088 KB
testcase_10 AC 18 ms
4,380 KB
testcase_11 AC 95 ms
10,744 KB
testcase_12 AC 53 ms
7,344 KB
testcase_13 AC 37 ms
10,748 KB
testcase_14 AC 177 ms
6,048 KB
testcase_15 AC 14 ms
10,288 KB
testcase_16 AC 191 ms
11,368 KB
testcase_17 AC 55 ms
5,812 KB
testcase_18 AC 36 ms
5,484 KB
testcase_19 AC 97 ms
10,696 KB
testcase_20 AC 88 ms
10,688 KB
testcase_21 AC 124 ms
10,936 KB
testcase_22 AC 199 ms
11,920 KB
testcase_23 AC 199 ms
11,916 KB
testcase_24 AC 197 ms
12,108 KB
testcase_25 AC 198 ms
11,972 KB
testcase_26 AC 197 ms
12,168 KB
testcase_27 AC 226 ms
12,104 KB
testcase_28 AC 226 ms
11,960 KB
testcase_29 AC 225 ms
11,956 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 = 0; 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);
    //st.disp();
    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);
            ans.push_back(p);
        } else {
            cin >> x;
            if (a == 0) {
                t[b - 1] = x;
            } else {
                d[b - 1] = x;
            }
            st.update_all(b - 1, t[b - 1], d[b - 1]);
        }
    }
    for (Node p : ans) {
        printf("%.9f %.9f\n", p.x, p.y);
    }
    //st.disp();
    return 0;
}
0