結果

問題 No.1226 I hate Robot Arms
ユーザー uni_python
提出日時 2020-09-13 00:16:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,175 ms / 2,000 ms
コード長 2,902 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 197,952 KB
最終ジャッジ日時 2025-01-02 15:07:35
合計ジャッジ時間 27,857 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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