結果

問題 No.1226 I hate Robot Arms
ユーザー KudeKude
提出日時 2020-09-11 22:59:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 2,361 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 169,472 KB
実行使用メモリ 9,544 KB
最終ジャッジ日時 2023-08-30 10:16:13
合計ジャッジ時間 13,381 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 91 ms
4,380 KB
testcase_03 AC 105 ms
4,536 KB
testcase_04 AC 126 ms
9,264 KB
testcase_05 AC 115 ms
9,220 KB
testcase_06 AC 275 ms
9,208 KB
testcase_07 AC 82 ms
4,380 KB
testcase_08 AC 42 ms
9,544 KB
testcase_09 AC 190 ms
4,628 KB
testcase_10 AC 23 ms
4,380 KB
testcase_11 AC 137 ms
9,196 KB
testcase_12 AC 75 ms
6,212 KB
testcase_13 AC 69 ms
9,148 KB
testcase_14 AC 226 ms
4,604 KB
testcase_15 AC 35 ms
9,208 KB
testcase_16 AC 273 ms
9,200 KB
testcase_17 AC 75 ms
4,596 KB
testcase_18 AC 52 ms
4,904 KB
testcase_19 AC 144 ms
9,204 KB
testcase_20 AC 129 ms
9,324 KB
testcase_21 AC 173 ms
9,196 KB
testcase_22 AC 280 ms
9,148 KB
testcase_23 AC 280 ms
9,208 KB
testcase_24 AC 281 ms
9,308 KB
testcase_25 AC 281 ms
9,324 KB
testcase_26 AC 281 ms
9,216 KB
testcase_27 AC 331 ms
9,312 KB
testcase_28 AC 331 ms
9,192 KB
testcase_29 AC 332 ms
9,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;

template<class T>
struct SegTree_A {
	std::vector<T> d;
	int sz;
	int base;
	const T e;
	T merge(const T& i, const T& j){return i+j;}
	SegTree_A(int size): sz(size), e() {
		int k = 1;
		while(sz > k) k <<= 1;
		d = std::vector<T>(2 * k - 1, e);
		base = k - 1;
	}
	void update_upper(int i) {
		while(i > 0) {
			i = (i-1)/2;
			d[i] = merge(d[i*2+1], d[i*2+2]);
		}
	}
	void add(int i, T x) {
		assert(0 <= i && i < sz);
		int t = base + i;
		d[t] = d[t] + x;
		update_upper(t);
	}
	void set(int i, T x) {
		assert(0 <= i && i < sz);
		int t = base + i;
		d[t] = x;
		update_upper(t);
	}
	T sum(int a, int b) {
		assert(0 <= a && a <= b && b <= sz);
		// sum up data in [a, b)
		return sum_sub(a, b, 0, 0, base+1);
	}
	T sum(int b) {return sum(0, b);}
	T sum_sub(int a, int b, int k, int l, int r) {
		if (b <= l || r <= a) return e;
		if (a <= l && r <= b) return d[k];
		int c = (l + r) / 2;
		return merge(
			sum_sub(a, b, 2*k+1, l, c),
			sum_sub(a, b, 2*k+2, c, r)
		);
	}
	T operator[](int i) {return d[base+i];}
};

struct P {
    double dx, dy, arg;
    P operator+(const P& t) const {
        return {
            dx + t.dx * cos(arg) - t.dy * sin(arg),
            dy + t.dx * sin(arg) + t.dy * cos(arg),
            arg + t.arg
        };
    }
    P(double x=0, double y=0, double a=0): dx(x), dy(y), arg(a) {}
};

int main() {
    int n, q;
    cin >> n >> q;
    SegTree_A<P> d(n);
    rep(i, n) d.set(i, {1, 0, 0});
    rep(_, q) {
        int qtype;
        cin >> qtype;
        if (qtype == 0) {
            int i, x;
            cin >> i >> x;
            i--;
            P t = d[i];
            double z = sqrt(t.dx * t.dx + t.dy * t.dy);
            double a = x * M_PI / 180;
            d.set(i, {z * cos(a), z * sin(a), a});
        } else if (qtype == 1) {
            int i, x;
            cin >> i >> x;
            i--;
            P t = d[i];
            d.set(i, {x * cos(t.arg), x * sin(t.arg), t.arg});
        } else {
            int i;
            cin >> i;
            P p = d.sum(i);
            printf("%.08f %.08f\n", p.dx, p.dy);
        }
    }
}
0