結果
問題 | No.1226 I hate Robot Arms |
ユーザー | Pachicobue |
提出日時 | 2020-09-11 22:20:47 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 13,958 bytes |
コンパイル時間 | 2,604 ms |
コンパイル使用メモリ | 216,324 KB |
実行使用メモリ | 14,016 KB |
最終ジャッジ日時 | 2024-06-10 10:21:34 |
合計ジャッジ時間 | 6,159 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
13,884 KB |
testcase_01 | AC | 6 ms
6,940 KB |
testcase_02 | TLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
ソースコード
#include <bits/stdc++.h> using ll = long long; using uint = unsigned int; using ull = unsigned long long; using ld = long double; template<typename T> using max_heap = std::priority_queue<T>; template<typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; constexpr int popcount(const ull v) { return v ? __builtin_popcountll(v) : 0; } constexpr int log2p1(const ull v) { return v ? 64 - __builtin_clzll(v) : 0; } constexpr int lsbp1(const ull v) { return __builtin_ffsll(v); } constexpr int clog(const ull v) { return v ? log2p1(v - 1) : 0; } constexpr ull ceil2(const ull v) { return 1ULL << clog(v); } constexpr ull floor2(const ull v) { return v ? (1ULL << (log2p1(v) - 1)) : 0ULL; } constexpr bool btest(const ull mask, const int ind) { return (mask >> ind) & 1ULL; } template<typename T> void bset(T& mask, const int ind) { mask |= ((T)1 << ind); } template<typename T> void breset(T& mask, const int ind) { mask &= ~((T)1 << ind); } template<typename T> void bflip(T& mask, const int ind) { mask ^= ((T)1 << ind); } template<typename T> void bset(T& mask, const int ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } template<typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4; template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; template<typename T> constexpr T TEN(const int n) { return n == 0 ? T{1} : TEN<T>(n - 1) * T{10}; } template<typename F> struct fix : F { fix(F&& f) : F{std::forward<F>(f)} {} template<typename... Args> auto operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); } }; template<typename T, int n, int i = 0> auto nd_array(int const (&szs)[n], const T x = T{}) { if constexpr (i == n) { return x; } else { return std::vector(szs[i], nd_array<T, n, i + 1>(szs, x)); } } class printer { public: printer(std::ostream& os_ = std::cout) : os{os_} { os << std::fixed << std::setprecision(15); } template<typename T> int operator()(const T& v) { return os << v, 0; } template<typename T> int operator()(const std::vector<T>& vs) { for (int i = 0; i < (int)vs.size(); i++) { os << (i ? " " : ""), this->operator()(vs[i]); } return 0; } template<typename T> int operator()(const std::vector<std::vector<T>>& vss) { for (int i = 0; i < (int)vss.size(); i++) { os << (0 <= i or i + 1 < (int)vss.size() ? "\n" : ""), this->operator()(vss[i]); } return 0; } template<typename T, typename... Args> int operator()(const T& v, const Args&... args) { return this->operator()(v), os << ' ', this->operator()(args...), 0; } template<typename... Args> int ln(const Args&... args) { return this->operator()(args...), os << '\n', 0; } template<typename... Args> int el(const Args&... args) { return this->operator()(args...), os << std::endl, 0; } template<typename... Args> int fmt(const std::string& s, const Args&... args) { return rec(s, 0, args...); } private: int rec(const std::string& s, int index) { return os << s.substr(index, s.size()), 0; } template<typename T, typename... Args> int rec(const std::string& s, int index, const T& v, const Args&... args) { return index == s.size() ? 0 : s[index] == '%' ? (this->operator()(v), rec(s, index + 1, args...)) : (os << s[index], rec(s, index + 1, v, args...)); } std::ostream& os; }; printer out; class scanner { public: scanner(std::istream& is_ = std::cin) : is{is_} { is.tie(nullptr), std::ios::sync_with_stdio(false); } template<typename T> T val() { T v; return is >> v, v; } template<typename T> T val(const T offset) { return val<T>() - offset; } template<typename T> std::vector<T> vec(const int n) { std::vector<T> vs(n); for (auto& v : vs) { v = val<T>(); } return vs; } template<typename T> std::vector<T> vec(const int n, const T offset) { std::vector<T> vs(n); for (auto& v : vs) { v = val<T>(offset); } return vs; } template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1) { std::vector<std::vector<T>> vss(n0); for (auto& vs : vss) { vs = vec<T>(n1); } return vss; } template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1, const T offset) { std::vector<std::vector<T>> vss(n0); for (auto& vs : vss) { vs = vec<T>(n1, offset); } return vss; } template<typename... Args> auto tup() { return std::tuple<std::decay_t<Args>...>{val<Args>()...}; } template<typename... Args> auto tup(const Args&... offsets) { return std::tuple<std::decay_t<Args>...>{val<Args>(offsets)...}; } private: std::istream& is; }; scanner in; # define SHOW(...) static_cast<void>(0) template<typename T, typename F> class dualseg { public: dualseg(const std::vector<T>& vs, F compose_, T id_) : sz{(int)vs.size()}, depth{(int)clog(sz)}, half{1 << depth}, ops(half << 1, id_), compose{compose_}, id{id_} { std::copy(vs.begin(), vs.end(), ops.begin() + half); } T get(const int a) const { assert(0 <= a and a < sz); T ans = id; for (int i = 0; i <= depth; i++) { ans = compose(ans, ops[(a + half) >> (depth - i)]); } return ans; } void set(int a, const T& f) { assert(0 <= a and a < sz); clean(a += half), clean(a + 1), ops[a] = f; } void act(int L, int R, const T& f) { assert(0 <= L and R <= sz); if (L >= R) { return; } clean(L += half), clean(R += half); for (; L < R; L >>= 1, R >>= 1) { if (L & 1) { update(L++, f); } if (R & 1) { update(--R, f); } } } friend std::ostream& operator<<(std::ostream& os, const dualseg& seg) { os << "["; for (int i = 0; i < seg.sz; i++) { os << seg.get(i) << (i + 1 == seg.sz ? "" : ","); } return (os << "]\n"); } private: void down(const int a) { update(a << 1, ops[a]), update(a << 1 | 1, ops[a]), ops[a] = id; } void clean(const int a) { const int b = (a / (a & -a)) >> 1; for (int i = 0; i < depth; i++) { const int v = a >> (depth - i); if (v > b) { break; } down(v); } } void update(const int a, const T& f) { ops[a] = compose(f, ops[a]); } const int sz, depth, half; std::vector<T> ops; F compose; T id; }; template<typename T, typename Merge> class segtree { public: segtree(const std::vector<T>& vs, const Merge merge_, const T e_) : size{(int)vs.size()}, half{(int)ceil2(size)}, vals(half << 1, e_), merge{merge_}, e{e_} { std::copy(vs.begin(), vs.end(), vals.begin() + half); for (int i = half - 1; i >= 1; i--) { up(i); } } T get(const int a) const { return assert(0 <= a and a < size), vals[a + half]; } void set(int a, const T& v) { assert(0 <= a and a < size); vals[a += half] = v; while (a >>= 1) { up(a); } } T fold(int l, int r) const { assert(0 <= l and l <= r and r <= size); T accl = e, accr = e; for (l += half, r += half; l < r; l >>= 1, r >>= 1) { if (l & 1) { accl = merge(accl, vals[l++]); } if (r & 1) { accr = merge(vals[--r], accr); } } return merge(accl, accr); } friend std::ostream& operator<<(std::ostream& os, const segtree& seg) { os << "["; for (int i = seg.half; i < seg.half + seg.size; i++) { os << seg.vals[i] << (i + 1 == seg.half + seg.size ? "" : ","); } return (os << "]\n"); } private: void up(const int i) { vals[i] = merge(vals[i << 1], vals[i << 1 | 1]); } const int size, half; std::vector<T> vals; const Merge merge; const T e; }; const auto min_merge = [](const auto& x1, const auto& x2) { return std::min(x1, x2); }; const auto max_merge = [](const auto& x1, const auto& x2) { return std::max(x1, x2); }; const auto minmax_merge = [](const auto& x1, const auto& x2) { return std::decay_t<decltype(x1)>{std::min(x1.first, x2.first), std::max(x1.second, x2.second)}; }; const auto sum_merge = [](const auto& x1, const auto& x2) { return x1 + x2; }; const auto affine_merge = [](const auto& x1, const auto& x2) { return std::decay_t<decltype(x1)>{x1.first * x2.first, x1.first * x2.second + x1.second}; }; const auto plus_comp = [](const auto& f1, const auto& f2) { return f1 + f2; }; const auto mult_comp = [](const auto& f1, const auto& f2) { return f1 * f2; }; const auto assign_comp = [](const auto f1, const auto f2) { return f1 == inf_v<std::decay_t<decltype(f1)>> ? f2 : f1; }; const auto affine_comp = [](const auto& f1, const auto& f2) { return std::decay_t<decltype(f1)>{f1.first * f2.first, f1.first * f2.second + f1.second}; }; const auto min_plus_apply = [](const auto& f, const auto& x, const auto&) { return x + f; }; const auto max_plus_apply = [](const auto& f, const auto& x, const auto&) { return x + f; }; const auto minmax_plus_apply = [](const auto& f, const auto& x, const auto&) { return std::decay_t<decltype(x)>{x.first + f, x.second + f}; }; const auto minmax_mult_apply = [](const auto& f, const auto& x, const auto&) { return f >= 0 ? std::decay<decltype(x)>{f * x.first, f * x.second} : std::decay_t<decltype(x)>{f * x.second, f * x.first}; }; const auto min_assign_apply = [](const auto& f, const auto& x, const auto&) { return f == inf_v<std::decay_t<decltype(f)>> ? x : f; }; const auto max_assign_apply = [](const auto& f, const auto& x, const auto&) { return f == inf_v<std::decay_t<decltype(f)>> ? x : f; }; const auto minmax_assign_apply = [](const auto& f, const auto& x, const auto&) { return f == inf_v<std::decay_t<decltype(f)>> ? x : std::decay_t<decltype(x)>{f, f}; }; const auto minmax_affine_apply = [](const auto& f, const auto x, const auto&) { return f.first >= 0 ? std::decay_t<decltype(x)>{x.first * f.first + f.second, x.second * f.first + f.second} : std::decay_t<decltype(x)>{x.second * f.first + f.second, x.first * f.first + f.second}; }; const auto sum_plus_apply = [](const auto& f, const auto& x, const auto& l) { return x + f * l; }; const auto sum_mult_apply = [](const auto& f, const auto& x, const auto&) { return x * f; }; const auto sum_assign_apply = [](const auto& f, const auto& x, const auto& l) { return f == inf_v<std::decay_t<decltype(f)>> ? x : f * l; }; const auto sum_affine_apply = [](const auto& f, const auto x, const auto& l) { return x * f.first + f.second * l; }; const auto reverse = [](const auto f) { return [f](const auto& x1, const auto& x2) { return f(x2, x1); }; }; int main() { using M = std::array<std::array<ld, 3>, 3>; auto comp = [&](const M& m1, const M& m2) { M ans; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { ld sum = 0; for (int k = 0; k < 3; k++) { sum += m1[i][k] * m2[k][j]; } ans[i][j] = sum; } } return ans; }; const M ID{{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}; const auto [N, Q] = in.tup<int, int>(); auto seg = dualseg(std::vector<M>(N + 1, ID), comp, ID); auto angs = segtree(std::vector<ld>(N + 1, 0), sum_merge, (ld)0); using pos = std::pair<ld, ld>; auto get = [&](const int i) -> pos { const M trans = seg.get(i); const ld x = trans[0][0] * i + trans[0][2]; const ld y = trans[1][0] * i + trans[1][2]; return {x, y}; }; std::vector<ld> lens(N, 1); auto dbg = [&]() { for (int i = 0; i <= N; i++) { const auto [x, y] = get(i); SHOW(i, x, y); } }; for (int q = 0; q < Q; q++) { dbg(); SHOW(seg); const int t = in.val<int>(); if (t == 0) { auto [i, x] = in.tup<int, ld>(1, 0); x = x / 180 * pi_v<ld>; const ld delta = x - angs.get(i); angs.set(i, x); M trans = ID; trans[0][0] = std::cos(delta); trans[0][1] = -std::sin(delta); trans[1][0] = std::sin(delta); trans[1][1] = std::cos(delta); const auto [xi, yi] = get(i); ld xc = xi, yc = yi; xc -= std::cos(delta) * xi - std::sin(delta) * yi; yc -= std::sin(delta) * xi + std::cos(delta) * yi; trans[0][2] = xc; trans[1][2] = yc; seg.act(i, N + 1, trans); } else if (t == 1) { const auto [i, x] = in.tup<int, ld>(1, 0); const ld delta = x - lens[i]; lens[i] = x; M trans = ID; const ld theta = angs.fold(0, i + 1); const ld xc = std::cos(theta) * delta; const ld yc = std::sin(theta) * delta; trans[0][2] = xc; trans[1][2] = yc; seg.act(i + 1, N + 1, trans); } else { const auto i = in.val<int>(); const auto [x, y] = get(i); out.ln(x, y); } } return 0; }