結果
| 問題 |
No.1226 I hate Robot Arms
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2020-09-27 04:02:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,030 ms / 2,000 ms |
| コード長 | 2,417 bytes |
| コンパイル時間 | 179 ms |
| コンパイル使用メモリ | 82,832 KB |
| 実行使用メモリ | 142,452 KB |
| 最終ジャッジ日時 | 2024-06-30 04:10:43 |
| 合計ジャッジ時間 | 27,671 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
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)))
Kazun