結果

問題 No.1226 I hate Robot Arms
ユーザー 👑 KazunKazun
提出日時 2020-09-27 04:02:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,079 ms / 2,000 ms
コード長 2,417 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 143,652 KB
最終ジャッジ日時 2023-09-12 16:15:27
合計ジャッジ時間 30,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,828 KB
testcase_01 AC 70 ms
71,996 KB
testcase_02 AC 460 ms
91,840 KB
testcase_03 AC 493 ms
96,776 KB
testcase_04 AC 580 ms
113,540 KB
testcase_05 AC 535 ms
112,092 KB
testcase_06 AC 1,027 ms
139,984 KB
testcase_07 AC 451 ms
91,864 KB
testcase_08 AC 300 ms
98,972 KB
testcase_09 AC 714 ms
109,512 KB
testcase_10 AC 295 ms
84,328 KB
testcase_11 AC 606 ms
116,040 KB
testcase_12 AC 427 ms
97,396 KB
testcase_13 AC 383 ms
104,816 KB
testcase_14 AC 829 ms
115,684 KB
testcase_15 AC 280 ms
99,276 KB
testcase_16 AC 1,004 ms
139,616 KB
testcase_17 AC 430 ms
95,136 KB
testcase_18 AC 344 ms
92,016 KB
testcase_19 AC 618 ms
117,380 KB
testcase_20 AC 569 ms
113,972 KB
testcase_21 AC 712 ms
122,740 KB
testcase_22 AC 1,052 ms
142,856 KB
testcase_23 AC 1,045 ms
143,032 KB
testcase_24 AC 1,031 ms
142,628 KB
testcase_25 AC 1,079 ms
143,316 KB
testcase_26 AC 1,063 ms
143,652 KB
testcase_27 AC 994 ms
138,732 KB
testcase_28 AC 992 ms
140,272 KB
testcase_29 AC 1,014 ms
137,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sin,cos,atan2,sqrt,radians,pi

class Segment_Tree():
    """
    このプログラム内は1-index
    """

    def __init__(self,L,calc,unit):
        """calcを演算とするリストLのSegment Treeを作成

        calc:演算(2変数関数,モノイド)
        unit:モノイドcalcの単位元 (xe=ex=xを満たすe)
        """
        self.calc=calc
        self.unit=unit

        N=len(L)
        d=max(1,(N-1).bit_length())
        k=1<<d

        self.data=[unit]*k+L+[unit]*(k-len(L))
        self.N=k
        self.depth=d

        for i in range(k-1,0,-1):
            self.data[i]=calc(self.data[i<<1],self.data[i<<1|1])

    def get(self,k,index=1):
        """第k要素を取得
        """
        assert 0<=k-index<self.N,"添字が範囲外"
        return self.data[k-index+self.N]

    def update(self,k,x,index=1):
        """第k要素をxに変え,更新を行う.

        k:数列の要素
        x:更新後の値
        """
        assert 0<=k-index<self.N,"添字が範囲外"
        m=(k-index)+self.N
        self.data[m]=x

        while m>1:
            m>>=1
            self.data[m]=self.calc(self.data[m<<1],self.data[m<<1|1])


    def product(self,From,To,index=1,left_closed=True,right_closed=True):
        L=(From-index)+self.N+(not left_closed)
        R=(To-index)+self.N+(right_closed)

        vL=self.unit
        vR=self.unit

        while L<R:
            if L&1:
                vL=self.calc(vL,self.data[L])
                L+=1

            if R&1:
                R-=1
                vR=self.calc(self.data[R],vR)

            L>>=1
            R>>=1

        return self.calc(vL,vR)

    def all_prod(self):
        return self.data[1]

def calc(X,Y):
    r1,t1,f1=X
    r2,t2,f2=Y

    p=r1*cos(t1)+r2*cos(t2+f1)
    q=r1*sin(t1)+r2*sin(t2+f1)

    return (sqrt(p*p+q*q),atan2(q,p),f1+f2)
#=================================================
N,Q=map(int,input().split())
A=[(1,0,0) for _ in range(N)]

S=Segment_Tree(A,calc,(0,0,0))
X=[]
for _ in range(Q):
    T=tuple(map(int,input().split()))

    if T[0]==0:
        _,i,theta=T
        r,t,f=S.get(i,1)
        S.update(i,(r,radians(theta),radians(theta)),1)
    elif T[0]==1:
        _,i,x=T
        r,t,f=S.get(i,1)
        S.update(i,(x,t,f),1)
    else:
        _,x=T
        r,t,f=S.product(1,x,1)
        X.append("{} {}".format(r*cos(t),r*sin(t)))
print("\n".join(map(str,X)))
0