結果

問題 No.1226 I hate Robot Arms
ユーザー Kiri8128Kiri8128
提出日時 2020-09-13 11:30:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,339 ms / 2,000 ms
コード長 4,860 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 124,136 KB
最終ジャッジ日時 2024-06-11 20:08:00
合計ジャッジ時間 33,198 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,008 KB
testcase_01 AC 40 ms
55,040 KB
testcase_02 AC 561 ms
89,088 KB
testcase_03 AC 748 ms
94,148 KB
testcase_04 AC 792 ms
103,840 KB
testcase_05 AC 751 ms
102,732 KB
testcase_06 AC 1,336 ms
122,064 KB
testcase_07 AC 561 ms
88,912 KB
testcase_08 AC 445 ms
98,816 KB
testcase_09 AC 860 ms
100,320 KB
testcase_10 AC 390 ms
83,120 KB
testcase_11 AC 848 ms
106,156 KB
testcase_12 AC 628 ms
95,696 KB
testcase_13 AC 544 ms
99,732 KB
testcase_14 AC 1,012 ms
105,292 KB
testcase_15 AC 356 ms
99,456 KB
testcase_16 AC 1,195 ms
121,744 KB
testcase_17 AC 610 ms
90,896 KB
testcase_18 AC 472 ms
87,828 KB
testcase_19 AC 764 ms
105,344 KB
testcase_20 AC 828 ms
106,304 KB
testcase_21 AC 960 ms
108,872 KB
testcase_22 AC 1,302 ms
123,496 KB
testcase_23 AC 1,252 ms
122,680 KB
testcase_24 AC 1,246 ms
122,356 KB
testcase_25 AC 1,339 ms
122,816 KB
testcase_26 AC 1,313 ms
124,136 KB
testcase_27 AC 1,167 ms
120,744 KB
testcase_28 AC 1,169 ms
121,472 KB
testcase_29 AC 1,151 ms
122,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
class SegmentTree():
    def __init__(self, init, unitX, unitA, f, g, h):
        self.f = f # (X, X) -> X
        self.g = g # (X, A, size) -> X
        self.h = h # (A, A) -> A
        self.unitX = unitX
        self.unitA = unitA
        self.f = f
        if type(init) == int:
            self.n = init
            self.n = 1 << (self.n - 1).bit_length()
            self.X = [unitX] * (self.n * 2)
            self.size = [1] * (self.n * 2)
        else:
            self.n = len(init)
            self.n = 1 << (self.n - 1).bit_length()
            self.X = [unitX] * self.n + init + [unitX] * (self.n - len(init))
            self.size = [0] * self.n + [1] * len(init) + [0] * (self.n - len(init))
            for i in range(self.n-1, 0, -1):
                self.X[i] = self.f(self.X[i*2], self.X[i*2|1])
    
        for i in range(self.n - 1, 0, -1):
            self.size[i] = self.size[i*2] + self.size[i*2|1]
        
        self.A = [unitA] * (self.n * 2)
        
    def update(self, i, x):
        i += self.n
        self.propagate_above(i)
        self.X[i] = x
        self.A[i] = unitA
        self.calc_above(i)
    
    def calc(self, i):
        return self.g(self.X[i], self.A[i], self.size[i])
    
    def calc_above(self, i):
        i >>= 1
        while i:
            self.X[i] = self.f(self.calc(i*2), self.calc(i*2|1))
            i >>= 1
    
    def propagate(self, i):
        self.X[i] = self.g(self.X[i], self.A[i], self.size[i])
        self.A[i*2] = self.h(self.A[i*2], self.A[i])
        self.A[i*2|1] = self.h(self.A[i*2|1], self.A[i])
        self.A[i] = self.unitA
        
    def propagate_above(self, i):
        H = i.bit_length()
        for h in range(H, 0, -1):
            self.propagate(i >> h)
    
    def propagate_all(self):
        for i in range(1, self.n):
            self.propagate(i)
    
    def getrange(self, l, r):
        l += self.n
        r += self.n
        l0, r0 = l // (l & -l), r // (r & -r) - 1
        self.propagate_above(l0)
        self.propagate_above(r0)
        
        al = self.unitX
        ar = self.unitX
        while l < r:
            if l & 1:
                al = self.f(al, self.calc(l))
                l += 1
            if r & 1:
                r -= 1
                ar = self.f(self.calc(r), ar)
            l >>= 1
            r >>= 1
        return self.f(al, ar)
    
    def getvalue(self, i):
        i += self.n
        self.propagate_above(i)
        return self.calc(i)
    
    def operate_range(self, l, r, a):
        l += self.n
        r += self.n
        l0, r0 = l // (l & -l), r // (r & -r) - 1
        self.propagate_above(l0)
        self.propagate_above(r0)
        while l < r:
            if l & 1:
                self.A[l] = self.h(self.A[l], a)
                l += 1
            if r & 1:
                r -= 1
                self.A[r] = self.h(self.A[r], a)
            l >>= 1
            r >>= 1
        
        self.calc_above(l0)
        self.calc_above(r0)
    
    def debug(self):
        print("self.n =", self.n)
        deX = []
        deA = []
        deS = []
        a, b = self.n, self.n * 2
        while b:
            deX.append(self.X[a:b])
            deA.append(self.A[a:b])
            deS.append(self.size[a:b])
            a, b = a//2, a
        print("--- debug ---")
        for d in deX[::-1]:
            print(d)
        print("--- ---")
        for d in deA[::-1]:
            print(d)
        print("--- ---")
        for d in deS[::-1]:
            print(d)
        print("--- ---")
    
    def debug(self):
        for i in range(min(self.n - 1, 10)):
            print(i, self.getvalue(i))
        for i in range(min(self.n, 11)):
            print(i, self.getrange(0, i))

from math import tan, sin, cos, pi, sqrt, atan2
f = lambda x, y: (x[0] + y[0], x[1] + y[1])
g = lambda x, a, s: (a[0] * x[0] - a[1] * x[1], a[1] * x[0] + a[0] * x[1])
h = lambda a, b: (a[0] * b[0] - a[1] * b[1], a[0] * b[1] + a[1] * b[0])

unitA = (1, 0) # * (a + bi), + (c + di)
unitX = (0, 0) # x, y
z = pi / 180
N, Q = map(int, input().split())
st = SegmentTree([(1, 0) for _ in range(N)], unitX, unitA, f, g, h)
for _ in range(Q):
    q = [int(a) for a in input().split()]
    if q[0] == 0:
        i, s = q[1:]
        s *= z
        i -= 1
        x, y = st.getvalue(i)
        r = sqrt(x**2 + y**2)
        t = atan2(y, x)
        if i == 0:
            u = 0
        else:
            x2, y2 = st.getvalue(i-1)
            u = atan2(y2, x2)
        st.operate_range(i, N, (cos((s - t + u)), sin((s - t + u))))
    elif q[0] == 1:
        i, s = q[1:]
        i -= 1
        x, y = st.getvalue(i)
        r = sqrt(x**2 + y**2)
        x *= s / r
        y *= s / r
        st.update(i, (x, y))
    else:
        i = q[1]
        print(*st.getrange(0, i))
0