結果

問題 No.1226 I hate Robot Arms
ユーザー msm1993msm1993
提出日時 2020-10-08 10:03:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 2,325 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 172,932 KB
実行使用メモリ 12,104 KB
最終ジャッジ日時 2023-09-27 11:41:12
合計ジャッジ時間 10,509 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 66 ms
4,912 KB
testcase_03 AC 74 ms
5,684 KB
testcase_04 AC 81 ms
10,680 KB
testcase_05 AC 70 ms
10,872 KB
testcase_06 AC 185 ms
11,820 KB
testcase_07 AC 58 ms
4,948 KB
testcase_08 AC 20 ms
10,472 KB
testcase_09 AC 136 ms
6,032 KB
testcase_10 AC 17 ms
4,376 KB
testcase_11 AC 89 ms
10,704 KB
testcase_12 AC 47 ms
7,260 KB
testcase_13 AC 34 ms
10,704 KB
testcase_14 AC 164 ms
6,068 KB
testcase_15 AC 14 ms
10,216 KB
testcase_16 AC 181 ms
11,060 KB
testcase_17 AC 50 ms
5,668 KB
testcase_18 AC 34 ms
5,504 KB
testcase_19 AC 87 ms
10,868 KB
testcase_20 AC 80 ms
10,516 KB
testcase_21 AC 117 ms
10,820 KB
testcase_22 AC 187 ms
11,852 KB
testcase_23 AC 185 ms
12,068 KB
testcase_24 AC 188 ms
12,004 KB
testcase_25 AC 186 ms
12,092 KB
testcase_26 AC 185 ms
12,104 KB
testcase_27 AC 210 ms
11,964 KB
testcase_28 AC 210 ms
11,900 KB
testcase_29 AC 217 ms
11,796 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