結果

問題 No.1226 I hate Robot Arms
ユーザー 👑 emthrmemthrm
提出日時 2020-09-14 17:41:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 2,972 bytes
コンパイル時間 2,436 ms
コンパイル使用メモリ 203,600 KB
実行使用メモリ 10,472 KB
最終ジャッジ日時 2023-09-04 00:45:38
合計ジャッジ時間 17,511 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 75 ms
4,380 KB
testcase_03 AC 86 ms
4,972 KB
testcase_04 AC 102 ms
9,712 KB
testcase_05 AC 95 ms
10,004 KB
testcase_06 AC 224 ms
10,236 KB
testcase_07 AC 68 ms
4,384 KB
testcase_08 AC 35 ms
9,764 KB
testcase_09 AC 156 ms
4,908 KB
testcase_10 AC 20 ms
4,380 KB
testcase_11 AC 113 ms
9,780 KB
testcase_12 AC 62 ms
6,496 KB
testcase_13 AC 57 ms
9,976 KB
testcase_14 AC 188 ms
4,912 KB
testcase_15 AC 29 ms
10,472 KB
testcase_16 AC 219 ms
9,972 KB
testcase_17 AC 62 ms
4,884 KB
testcase_18 AC 43 ms
4,920 KB
testcase_19 AC 119 ms
9,728 KB
testcase_20 AC 106 ms
9,708 KB
testcase_21 AC 142 ms
9,972 KB
testcase_22 AC 229 ms
10,028 KB
testcase_23 AC 234 ms
10,056 KB
testcase_24 AC 232 ms
10,012 KB
testcase_25 AC 231 ms
9,988 KB
testcase_26 AC 231 ms
10,044 KB
testcase_27 AC 277 ms
10,256 KB
testcase_28 AC 275 ms
9,984 KB
testcase_29 AC 275 ms
10,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Monoid, typename Fn>
struct SegmentTree {
  SegmentTree(int sz, Fn fn, const Monoid UNITY) : fn(fn), UNITY(UNITY) {
    init(sz);
    dat.assign(n << 1, UNITY);
  }

  SegmentTree(const std::vector<Monoid> &a, Fn fn, const Monoid UNITY) : fn(fn), UNITY(UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize(n << 1);
    for (int i = 0; i < a_sz; ++i) dat[i + n] = a[i];
    for (int i = n - 1; i > 0; --i) dat[i] = fn(dat[i << 1], dat[(i << 1) + 1]);
  }

  void update(int node, Monoid val) {
    node += n;
    dat[node] = val;
    while (node >>= 1) dat[node] = fn(dat[node << 1], dat[(node << 1) + 1]);
  }

  Monoid query(int left, int right) const {
    Monoid l_res = UNITY, r_res = UNITY;
    for (left += n, right += n; left < right; left >>= 1, right >>= 1) {
      if (left & 1) l_res = fn(l_res, dat[left++]);
      if (right & 1) r_res = fn(dat[--right], r_res);
    }
    return fn(l_res, r_res);
  }

  Monoid operator[](const int idx) const { return dat[idx + n]; }

private:
  int n = 1;
  Fn fn;
  const Monoid UNITY;
  std::vector<Monoid> dat;

  void init(int sz) { while (n < sz) n <<= 1; }
};

int main() {
  struct Node {
    double x, y, angle;
  };
  auto fn = [](Node a, Node b) {
    double x = a.x + cos(a.angle) * b.x - sin(a.angle) * b.y;
    double y = a.y + sin(a.angle) * b.x + cos(a.angle) * b.y;
    return Node{x, y, a.angle + b.angle};
  };

  int n, q; cin >> n >> q;
  vector angle(n, 0), len(n, 1);
  SegmentTree seg(n, fn, Node{0, 0, 0});
  REP(i, n) seg.update(i, Node{1, 0, 0});
  while (q--) {
    int query, i; cin >> query >> i; --i;
    if (query == 0) {
      int x; cin >> x;
      angle[i] = x;
      seg.update(i, Node{len[i] * cos(x * M_PI / 180), len[i] * sin(x * M_PI / 180), x * M_PI / 180});
    } else if (query == 1) {
      int x; cin >> x;
      len[i] = x;
      seg.update(i, Node{x * cos(angle[i] * M_PI / 180), x * sin(angle[i] * M_PI / 180), angle[i] * M_PI / 180});
    } else if (query == 2) {
      Node ans = seg.query(0, i + 1);
      cout << ans.x << ' ' << ans.y << '\n';
    }
  }
  return 0;
}
0