結果

問題 No.1226 I hate Robot Arms
ユーザー tnakao0123tnakao0123
提出日時 2020-09-12 22:29:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 2,796 bytes
コンパイル時間 2,805 ms
コンパイル使用メモリ 94,880 KB
実行使用メモリ 9,912 KB
最終ジャッジ日時 2023-08-30 19:22:14
合計ジャッジ時間 8,473 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,820 KB
testcase_01 AC 4 ms
9,652 KB
testcase_02 AC 41 ms
9,652 KB
testcase_03 AC 45 ms
9,912 KB
testcase_04 AC 48 ms
9,652 KB
testcase_05 AC 42 ms
9,684 KB
testcase_06 AC 108 ms
9,796 KB
testcase_07 AC 38 ms
9,812 KB
testcase_08 AC 14 ms
9,684 KB
testcase_09 AC 81 ms
9,576 KB
testcase_10 AC 13 ms
9,652 KB
testcase_11 AC 53 ms
9,644 KB
testcase_12 AC 31 ms
9,684 KB
testcase_13 AC 23 ms
9,856 KB
testcase_14 AC 97 ms
9,808 KB
testcase_15 AC 9 ms
9,604 KB
testcase_16 AC 105 ms
9,580 KB
testcase_17 AC 33 ms
9,580 KB
testcase_18 AC 23 ms
9,652 KB
testcase_19 AC 55 ms
9,908 KB
testcase_20 AC 51 ms
9,684 KB
testcase_21 AC 67 ms
9,656 KB
testcase_22 AC 108 ms
9,588 KB
testcase_23 AC 110 ms
9,816 KB
testcase_24 AC 113 ms
9,796 KB
testcase_25 AC 108 ms
9,688 KB
testcase_26 AC 109 ms
9,812 KB
testcase_27 AC 136 ms
9,808 KB
testcase_28 AC 137 ms
9,816 KB
testcase_29 AC 136 ms
9,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1226.cc:  No.1226 I hate Robot Arms - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
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 <typename T, const int MAX_E2>
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<Elm,MAX_E2> 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;
}
0