/* -*- coding: utf-8 -*- * * 1226.cc: No.1226 I hate Robot Arms - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_E2 = 1 << 18; // = 262144 const double PI = acos(-1.0); /* typedef */ static double cs[360], ss[360]; struct Elm { double x, y; int l, deg; Elm(): x(1.0), y(0.0), l(1), deg(0) {} Elm(double _x, double _y, int _l, int _deg): x(_x), y(_y), l(_l), deg(_deg) {} void _set() { x = l * cs[deg], y = l * ss[deg]; } void setdeg(int _deg) { deg = _deg; _set(); } void setl(int _l) { l = _l, _set(); } Elm operator+(const Elm &e) const { double dx = cs[deg] * e.x - ss[deg] * e.y; double dy = ss[deg] * e.x + cs[deg] * e.y; return Elm(x + dx, y + dy, 0.0, (deg + e.deg) % 360); } }; template struct SegTreeAdd { int e2; T nodes[MAX_E2], defv; SegTreeAdd() {} void init(int n, T _defv) { defv = _defv; for (e2 = 1; e2 < n; e2 <<= 1); fill(nodes, nodes + MAX_E2, defv); } T &get(int i) { return nodes[e2 - 1 + i]; } void seti(int i, T v) { get(i) = v; } void setall() { for (int j = e2 - 2; j >= 0; j--) nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2]; } void set(int i, T v) { int j = e2 - 1 + i; nodes[j] = v; while (j > 0) { j = (j - 1) / 2; nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2]; } } T add_range(int r0, int r1, int k, int i0, int i1) { if (r1 <= i0 || i1 <= r0) return defv; if (r0 <= i0 && i1 <= r1) return nodes[k]; int im = (i0 + i1) / 2; T v0 = add_range(r0, r1, k * 2 + 1, i0, im); T v1 = add_range(r0, r1, k * 2 + 2, im, i1); return v0 + v1; } T add_range(int r0, int r1) { return add_range(r0, r1, 0, 0, e2); } }; /* global variables */ SegTreeAdd st; /* subroutines */ /* main */ int main() { for (int i = 0; i < 360; i++) { double th = PI * i / 180; cs[i] = cos(th), ss[i] = sin(th); } int n, q; scanf("%d%d", &n, &q); Elm e0(0.0, 0.0, 0, 0), e1(1.0, 0.0, 1, 0); st.init(n, e0); for (int i = 0; i < n; i++) st.seti(i, e1); st.setall(); while (q--) { int op, i; scanf("%d%d", &op, &i); i--; if (op == 0 || op == 1) { int x; scanf("%d", &x); Elm e = st.get(i); if (op == 0) e.setdeg(x); else e.setl(x); st.set(i, e); } else { Elm e = st.add_range(0, i + 1); printf("%.9lf %.9lf\n", e.x, e.y); } } return 0; }