結果

問題 No.1226 I hate Robot Arms
ユーザー uni_pythonuni_python
提出日時 2020-09-13 00:16:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,239 ms / 2,000 ms
コード長 2,902 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 199,140 KB
最終ジャッジ日時 2023-08-30 19:39:06
合計ジャッジ時間 30,253 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,592 KB
testcase_01 AC 73 ms
71,732 KB
testcase_02 AC 544 ms
100,992 KB
testcase_03 AC 572 ms
112,464 KB
testcase_04 AC 663 ms
150,316 KB
testcase_05 AC 620 ms
149,480 KB
testcase_06 AC 1,129 ms
191,612 KB
testcase_07 AC 529 ms
103,240 KB
testcase_08 AC 345 ms
125,804 KB
testcase_09 AC 736 ms
129,360 KB
testcase_10 AC 298 ms
87,392 KB
testcase_11 AC 704 ms
152,608 KB
testcase_12 AC 517 ms
114,752 KB
testcase_13 AC 458 ms
134,876 KB
testcase_14 AC 909 ms
140,452 KB
testcase_15 AC 307 ms
124,248 KB
testcase_16 AC 1,114 ms
191,704 KB
testcase_17 AC 494 ms
110,384 KB
testcase_18 AC 424 ms
104,256 KB
testcase_19 AC 735 ms
154,936 KB
testcase_20 AC 708 ms
149,560 KB
testcase_21 AC 820 ms
159,328 KB
testcase_22 AC 1,169 ms
197,360 KB
testcase_23 AC 1,117 ms
197,912 KB
testcase_24 AC 1,198 ms
196,068 KB
testcase_25 AC 1,239 ms
198,648 KB
testcase_26 AC 1,171 ms
199,140 KB
testcase_27 AC 1,002 ms
181,056 KB
testcase_28 AC 977 ms
179,664 KB
testcase_29 AC 964 ms
180,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    from math import sin,cos,pi
    PI=pi
    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)
        
    def ch(X):
        return (X*PI)/180

    def func(a,b):
        [x1,y1],t1 = a
        [x2,y2],t2 = b
        
        x=x1 + x2*cos(t1) - y2*sin(t1)
        y=y1 + x2*sin(t1) + y2*cos(t1)

        th=(t1+t2)
        # print("a:",a,"  b:",b)
        # print([[x,y],th*180/PI])
        return [[x,y],th]
    
    N,Q=MI()
    A=[[[1,0],0]for _ in range(N)]
    seg=SegmentTree(A, func, [[0,0],0])
    ds=[1]*N
    ths=[0]*N
    
    for _ in range(Q):
        q=LI()
        if q[0]==0:
            i=q[1]-1
            th=ch(q[2])
            ths[i]=th
            dn=ds[i]
            v=[dn*cos(th),dn*sin(th)]
            seg.update(i,[v,th])
            
        elif q[0]==1:
            i=q[1]-1
            d=q[2]
            ds[i]=d
            thn=ths[i]
            v=[d*cos(thn), d*sin(thn)]
            
            seg.update(i,[v,thn])

        else:
            #print("++++++++++++++")
            i=q[1]-1
            vn,tn=seg.get_segment(0,i+1)
            print(*vn)
            

            
    # for i in range(N):
    #     vn,thn=seg.query(i,i+1)
    #     print(vn,thn*180/PI)
            
            
                
            
        

main()
0