結果

問題 No.1226 I hate Robot Arms
ユーザー 👑 KazunKazun
提出日時 2020-09-27 04:07:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,010 ms / 2,000 ms
コード長 2,429 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 86,568 KB
実行使用メモリ 143,288 KB
最終ジャッジ日時 2023-09-12 16:25:36
合計ジャッジ時間 27,768 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,776 KB
testcase_01 AC 73 ms
71,828 KB
testcase_02 AC 486 ms
91,264 KB
testcase_03 AC 484 ms
96,908 KB
testcase_04 AC 553 ms
113,140 KB
testcase_05 AC 512 ms
111,656 KB
testcase_06 AC 976 ms
139,392 KB
testcase_07 AC 424 ms
91,980 KB
testcase_08 AC 290 ms
98,476 KB
testcase_09 AC 684 ms
107,568 KB
testcase_10 AC 298 ms
83,984 KB
testcase_11 AC 583 ms
115,276 KB
testcase_12 AC 423 ms
96,916 KB
testcase_13 AC 380 ms
104,304 KB
testcase_14 AC 793 ms
115,468 KB
testcase_15 AC 274 ms
98,944 KB
testcase_16 AC 951 ms
139,448 KB
testcase_17 AC 429 ms
95,204 KB
testcase_18 AC 339 ms
91,504 KB
testcase_19 AC 596 ms
117,120 KB
testcase_20 AC 549 ms
113,584 KB
testcase_21 AC 691 ms
120,324 KB
testcase_22 AC 968 ms
142,548 KB
testcase_23 AC 994 ms
143,224 KB
testcase_24 AC 957 ms
139,904 KB
testcase_25 AC 1,010 ms
142,996 KB
testcase_26 AC 982 ms
143,288 KB
testcase_27 AC 933 ms
138,308 KB
testcase_28 AC 946 ms
137,796 KB
testcase_29 AC 927 ms
137,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    @classmethod
    def calc(cls,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)

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

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

        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]=self.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]
#=================================================
N,Q=map(int,input().split())
A=[(1,0,0) for _ in range(N)]

S=Segment_Tree(A)
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