結果

問題 No.1226 I hate Robot Arms
ユーザー packer_jppacker_jp
提出日時 2020-09-11 22:47:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 413 ms / 2,000 ms
コード長 7,942 bytes
コンパイル時間 2,515 ms
コンパイル使用メモリ 211,724 KB
実行使用メモリ 12,396 KB
最終ジャッジ日時 2024-06-10 10:32:07
合計ジャッジ時間 16,217 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 126 ms
6,944 KB
testcase_03 AC 141 ms
6,944 KB
testcase_04 AC 154 ms
11,624 KB
testcase_05 AC 138 ms
12,084 KB
testcase_06 AC 342 ms
12,068 KB
testcase_07 AC 116 ms
6,940 KB
testcase_08 AC 35 ms
11,804 KB
testcase_09 AC 262 ms
6,940 KB
testcase_10 AC 32 ms
6,940 KB
testcase_11 AC 167 ms
11,460 KB
testcase_12 AC 97 ms
7,680 KB
testcase_13 AC 65 ms
12,000 KB
testcase_14 AC 324 ms
6,940 KB
testcase_15 AC 22 ms
11,796 KB
testcase_16 AC 350 ms
12,152 KB
testcase_17 AC 100 ms
6,940 KB
testcase_18 AC 65 ms
6,940 KB
testcase_19 AC 176 ms
11,896 KB
testcase_20 AC 163 ms
11,436 KB
testcase_21 AC 214 ms
11,364 KB
testcase_22 AC 397 ms
12,396 KB
testcase_23 AC 351 ms
12,216 KB
testcase_24 AC 351 ms
12,028 KB
testcase_25 AC 351 ms
12,304 KB
testcase_26 AC 352 ms
12,228 KB
testcase_27 AC 413 ms
12,156 KB
testcase_28 AC 409 ms
12,264 KB
testcase_29 AC 406 ms
12,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;


#include <algorithm>

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

namespace atcoder {

    namespace internal {

// @param n `0 <= n`
// @return minimum non-negative `x` s.t. `n <= 2**x`
        int ceil_pow2(int n) {
            int x = 0;
            while ((1U << x) < (unsigned int) (n)) { x++; }
            return x;
        }

// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
        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;

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int x) { return (x > 0) - (x < 0); }
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T> T sq(T x) { return x * x; }
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

using S = tuple<double, double, double>;
S e() { return {0, 0, 0}; }
S op(S a, S b) {
    auto[ra, ta, fa]=a;
    auto[rb, tb, fb]=b;
    tb += fa, fb += fa;
    return {sqrt(sq(ra * cos(ta) + rb * cos(tb)) + sq(ra * sin(ta) + rb * sin(tb))),
            atan2(ra * sin(ta) + rb * sin(tb), ra * cos(ta) + rb * cos(tb)), fb};
}
signed main() {
    int N, Q;
    cin >> N >> Q;
    vector<S> src(N, {1, 0, 0});
    segtree<S, op, e> st(src);
    while (Q--) {
        int q;
        cin >> q;
        if (q == 0) {
            int i, x;
            cin >> i >> x, i--;
            auto[r, t, f]=st.get(i);
            t = x * PI / 180, f = x * PI / 180;
            st.set(i, {r, t, f});
        } else if (q == 1) {
            int i, x;
            cin >> i >> x, i--;
            auto[r, t, f]=st.get(i);
            r = x;
            st.set(i, {r, t, f});
        } else if (q == 2) {
            int i;
            cin >> i;
            auto[r, t, f]=st.prod(0, i);
            cout << r * cos(t) << " " << r * sin(t) << endl;
        }
    }
}
0