結果

問題 No.1226 I hate Robot Arms
ユーザー MitarushiMitarushi
提出日時 2020-09-12 08:38:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,065 ms / 2,000 ms
コード長 2,076 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 120,016 KB
最終ジャッジ日時 2023-08-30 11:32:21
合計ジャッジ時間 28,881 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,736 KB
testcase_01 AC 76 ms
71,948 KB
testcase_02 AC 531 ms
88,108 KB
testcase_03 AC 596 ms
91,964 KB
testcase_04 AC 641 ms
103,012 KB
testcase_05 AC 623 ms
104,320 KB
testcase_06 AC 972 ms
116,456 KB
testcase_07 AC 507 ms
88,700 KB
testcase_08 AC 417 ms
95,492 KB
testcase_09 AC 741 ms
97,000 KB
testcase_10 AC 325 ms
82,900 KB
testcase_11 AC 659 ms
104,476 KB
testcase_12 AC 490 ms
92,580 KB
testcase_13 AC 487 ms
99,700 KB
testcase_14 AC 829 ms
100,020 KB
testcase_15 AC 340 ms
95,964 KB
testcase_16 AC 985 ms
117,512 KB
testcase_17 AC 499 ms
90,744 KB
testcase_18 AC 430 ms
88,452 KB
testcase_19 AC 656 ms
105,288 KB
testcase_20 AC 618 ms
102,392 KB
testcase_21 AC 720 ms
107,744 KB
testcase_22 AC 1,040 ms
119,920 KB
testcase_23 AC 1,048 ms
118,884 KB
testcase_24 AC 1,065 ms
120,016 KB
testcase_25 AC 1,003 ms
119,168 KB
testcase_26 AC 1,060 ms
119,336 KB
testcase_27 AC 961 ms
112,612 KB
testcase_28 AC 984 ms
114,240 KB
testcase_29 AC 983 ms
113,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sin, cos, pi
p = pi / 180


class SegmentTree:
    def __init__(self, a, func=max, one=-10 ** 18):
        self.logn = (len(a) - 1).bit_length()
        self.n = 1 << self.logn
        self.func = func
        self.one = one

        self.b = [self.one] * (2 * self.n - 1)
        for i, j in enumerate(a):
            self.b[i + self.n - 1] = j
        for i in reversed(range(self.n - 1)):
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_item(self, i):
        return self.b[i + self.n - 1]

    def update(self, index, x):
        i = index + self.n - 1
        self.b[i] = x
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def update_func(self, index, x):
        i = index + self.n - 1
        self.b[i] = self.func(self.b[i], x)
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_segment(self, l, r):
        l += self.n
        r += self.n
        s = self.one
        t = self.one
        while l < r:
            if l & 1:
                s = self.func(s, self.b[l - 1])
                l += 1
            if r & 1:
                r -= 1
                t = self.func(self.b[r - 1], t)
            l >>= 1
            r >>= 1
        return self.func(s, t)


n, q = map(int, input().split())


def merge(a, b):
    (x1, y1), t1 = a
    (x2, y2), t2 = b
    x = x1 + x2*cos(t1*p) - y2*sin(t1*p)
    y = y1 + x2*sin(t1*p) + y2 * cos(t1*p)
    return (x, y), t1+t2


seg = SegmentTree([((1, 0), 0) for _ in range(n)], merge, [[0, 0], 0])
d = [1] * n
th = [0] * n
for _ in range(q):
    qu, *x = map(int, input().split())
    if qu == 2:
        print(*seg.get_segment(0, x[0])[0])
    else:
        a, b = x
        if qu == 0:
            th[a-1] = b
            c = ((d[a-1] * cos(b*p), d[a-1] * sin(b*p)), b)
        else:
            d[a-1] = b
            e = th[a-1]
            c = ((b * cos(e*p), b * sin(e*p)), e)
        seg.update(a-1, c)
0