結果

問題 No.1226 I hate Robot Arms
ユーザー lorent_kyoprolorent_kyopro
提出日時 2020-11-02 13:38:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 5,564 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 203,664 KB
実行使用メモリ 11,840 KB
最終ジャッジ日時 2023-09-29 11:49:14
合計ジャッジ時間 8,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 60 ms
4,380 KB
testcase_03 AC 67 ms
5,124 KB
testcase_04 AC 71 ms
11,112 KB
testcase_05 AC 64 ms
11,268 KB
testcase_06 AC 166 ms
11,368 KB
testcase_07 AC 54 ms
4,376 KB
testcase_08 AC 20 ms
11,176 KB
testcase_09 AC 124 ms
5,132 KB
testcase_10 AC 15 ms
4,376 KB
testcase_11 AC 82 ms
10,800 KB
testcase_12 AC 44 ms
7,476 KB
testcase_13 AC 33 ms
11,840 KB
testcase_14 AC 149 ms
5,176 KB
testcase_15 AC 14 ms
11,636 KB
testcase_16 AC 161 ms
11,832 KB
testcase_17 AC 47 ms
5,608 KB
testcase_18 AC 32 ms
5,308 KB
testcase_19 AC 83 ms
11,044 KB
testcase_20 AC 75 ms
10,844 KB
testcase_21 AC 106 ms
10,904 KB
testcase_22 AC 170 ms
11,512 KB
testcase_23 AC 167 ms
11,632 KB
testcase_24 AC 170 ms
11,632 KB
testcase_25 AC 169 ms
11,644 KB
testcase_26 AC 167 ms
11,584 KB
testcase_27 AC 198 ms
11,572 KB
testcase_28 AC 201 ms
11,636 KB
testcase_29 AC 196 ms
11,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>

#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}

int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}

}  // namespace internal

}  // namespace atcoder

#include <cassert>
#include <vector>

namespace atcoder {

template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    segtree(int n) : segtree(std::vector<S>(n, e())) {}
    segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = internal::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};

}  // namespace atcoder

using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353;
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}
__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

struct S {
    complex<double> point;
    double theta;
};
S op(S a, S b) {
    b.point *= polar(1.0, a.theta);
    return {a.point + b.point, a.theta + b.theta};
}
S e() { return {complex<double>(0, 0), 0}; };

int main() {
    int n, q;
    cin >> n >> q;
    vector<S> ps(n, {complex<double>(1, 0), 0});
    segtree<S, op, e> seg(ps);
    while (q--) {
        int t, i, x;
        cin >> t;
        if (t == 0) {
            cin >> i >> x;
            --i;
            S p = seg.get(i);
            double d = abs(p.point);
            double theta = x * acos(-1) / 180;
            p.point = polar(d, theta);
            p.theta = theta;
            seg.set(i, p);
        } else if (t == 1) {
            cin >> i >> x;
            --i;
            S p = seg.get(i);
            p.point = polar((double)x, p.theta);
            seg.set(i, p);
        } else {
            cin >> i;
            --i;
            S p = seg.prod(0, i+1);
            cout << fixed << setprecision(9) << p.point.real() << ' ' << p.point.imag() << '\n';
        }
    }
}
0