結果

問題 No.1226 I hate Robot Arms
ユーザー so4649so4649
提出日時 2021-01-06 19:22:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,606 ms / 2,000 ms
コード長 6,243 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 177,712 KB
最終ジャッジ日時 2024-11-07 05:38:28
合計ジャッジ時間 38,775 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,760 KB
testcase_01 AC 47 ms
55,040 KB
testcase_02 AC 666 ms
94,104 KB
testcase_03 AC 746 ms
103,132 KB
testcase_04 AC 906 ms
130,900 KB
testcase_05 AC 832 ms
128,608 KB
testcase_06 AC 1,557 ms
171,508 KB
testcase_07 AC 647 ms
95,368 KB
testcase_08 AC 516 ms
109,720 KB
testcase_09 AC 1,003 ms
116,516 KB
testcase_10 AC 425 ms
85,340 KB
testcase_11 AC 950 ms
133,092 KB
testcase_12 AC 648 ms
104,904 KB
testcase_13 AC 609 ms
118,640 KB
testcase_14 AC 1,200 ms
126,868 KB
testcase_15 AC 438 ms
106,900 KB
testcase_16 AC 1,535 ms
173,692 KB
testcase_17 AC 661 ms
101,096 KB
testcase_18 AC 544 ms
96,216 KB
testcase_19 AC 951 ms
135,416 KB
testcase_20 AC 884 ms
131,384 KB
testcase_21 AC 1,081 ms
140,904 KB
testcase_22 AC 1,576 ms
177,712 KB
testcase_23 AC 1,606 ms
175,192 KB
testcase_24 AC 1,582 ms
176,828 KB
testcase_25 AC 1,577 ms
175,408 KB
testcase_26 AC 1,604 ms
176,016 KB
testcase_27 AC 1,600 ms
169,624 KB
testcase_28 AC 1,601 ms
171,932 KB
testcase_29 AC 1,547 ms
169,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 遅延セグ木解

class LazySegmentTree:
    def __init__(self, op_X, e_X, mapping, compose, id_M, N, array=None):
        __slots__ = ["op_X","e_X","mapping","compose","id_M","N","log","N0","data","lazy"]
        self.e_X = e_X; self.op_X = op_X; self.mapping = mapping; self.compose = compose; self.id_M = id_M
        self.N = N
        self.log = (N-1).bit_length()
        self.N0 = 1<<self.log
        self.data = [e_X]*(2*self.N0)
        self.lazy = [id_M]*self.N0
        if array is not None:
            assert N == len(array)
            self.data[self.N0:self.N0+self.N] = array
            for i in range(self.N0-1,0,-1): self.update(i)
 
    # 1点更新
    def point_set(self, p, x):
        p += self.N0
        for i in range(self.log, 0,-1):
            self.push(p>>i)
        self.data[p] = x
        for i in range(1, self.log + 1):
            self.update(p>>i)
 
    # 1点取得
    def point_get(self, p):
        p += self.N0
        for i in range(self.log, 0, -1):
            self.push(p>>i)
        return self.data[p]
 
    # 半開区間[L,R)をopでまとめる
    def prod(self, l, r):
        if l == r: return self.e_X
        l += self.N0
        r += self.N0
        for i in range(self.log, 0, -1):
            if (l>>i)<<i != l:
                self.push(l>>i)
            if (r>>i)<<i != r:
                self.push(r>>i)
 
        sml = smr = self.e_X
        while l < r:
            if l & 1: 
                sml = self.op_X(sml, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op_X(self.data[r], smr)
            l >>= 1
            r >>= 1
        return self.op_X(sml, smr)
 
    # 全体をopでまとめる
    def all_prod(self): return self.data[1]
 
    # 1点作用
    def apply(self, p, f):
        p += self.N0
        for i in range(self.log, 0, -1):
            self.push(p>>i)
        self.data[p] = self.mapping(f, self.data[p])
        for i in range(1, self.log + 1):
            self.update(p>>i)
 
    # 区間作用
    def apply(self, l, r, f):
        if l == r: return
        l += self.N0
        r += self.N0
        for i in range(self.log, 0, -1):
            if (l>>i)<<i != l:
                self.push(l>>i)
            if (r>>i)<<i != r:
                self.push((r-1)>>i)
 
        l2, r2 = l, r
        while l < r:
            if l & 1: 
                self.all_apply(l, f)
                l += 1
            if r & 1:
                r -= 1
                self.all_apply(r, f)
            l >>= 1
            r >>= 1
 
        l, r = l2, r2
        for i in range(1, self.log + 1):
            if (l>>i)<<i != l:
                self.update(l>>i)
            if (r>>i)<<i != r:
                self.update((r-1)>>i)
     
    """
    始点 l を固定
    f(x_l*...*x_{r-1}) が True になる最大の r 
    つまり TTTTFFFF となるとき、F となる最小の添え字
    存在しない場合 n が返る
    f(e_M) = True でないと壊れる
    """
    def max_right(self, l, g):
        if l == self.N: return self.N
        l += self.N0
        for i in range(self.log, 0, -1): self.push(l>>i)
        sm = self.e_X
        while True:
            while l&1 == 0:
                l >>= 1
            if not g(self.op_X(sm, self.data[l])):
                while l < self.N0:
                    self.push(l)
                    l *= 2
                    if g(self.op_X(sm, self.data[l])):
                        sm = self.op_X(sm, self.data[l])
                        l += 1
                return l - self.N0
            sm = self.op_X(sm, self.data[l])
            l += 1
            if l&-l == l: break
        return self.N
 
    """
    終点 r を固定
    f(x_l*...*x_{r-1}) が True になる最小の l
    つまり FFFFTTTT となるとき、T となる最小の添え字
    存在しない場合 r が返る
    f(e_M) = True でないと壊れる
    """
    def min_left(self, r, g):
        if r == 0: return 0
        r += self.N0
        for i in range(self.log, 0, -1): self.push((r-1)>>i)
        sm = self.e_X
        while True:
            r -= 1
            while r>1 and r&1:
                r >>= 1
            if not g(self.op_X(self.data[r], sm)):
                while r < self.N0:
                    self.push(r)
                    r = 2*r + 1
                    if g(self.op_X(self.data[r], sm)):
                        sm = self.op_X(self.data[r], sm)
                        r -= 1
                return r + 1 - self.N0
            sm = self.op_X(self.data[r], sm)
            if r&-r == r: break
        return 0
        
    # 以下内部関数
    def update(self, k):
        self.data[k] = self.op_X(self.data[2*k], self.data[2*k+1])
    
    def all_apply(self, k, f):
        self.data[k] = self.mapping(f, self.data[k])
        if k < self.N0:
            self.lazy[k] = self.compose(f, self.lazy[k])
 
    def push(self, k): #propagate と同じ
        if self.lazy[k] is self.id_M: return
        self.data[2*k  ] = self.mapping(self.lazy[k], self.data[2*k])
        self.data[2*k+1] = self.mapping(self.lazy[k], self.data[2*k+1])
        if 2*k < self.N0:
            self.lazy[2*k]   = self.compose(self.lazy[k], self.lazy[2*k])
            self.lazy[2*k+1] = self.compose(self.lazy[k], self.lazy[2*k+1])
        self.lazy[k] = self.id_M

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

n,q = map(int,input().split())

def f(a,b):
    x = a[0]+b[0]
    y = a[1]+b[1]
    return [x,y]

def mapping(a,b):
    rotate = [[cos(radians(a)),-sin(radians(a))],[sin(radians(a)),cos(radians(a))]]
    x = b[0]*rotate[0][0]+b[1]*rotate[0][1]
    y = b[0]*rotate[1][0]+b[1]*rotate[1][1]
    return [x,y]

def compose(a,b):
    return (a+b)%360

seg = LazySegmentTree(f,[0,0],mapping,compose,0,n,[[1,0] for i in range(n)])
arg = [0]*n
length = [1]*n

for _ in range(q):
    query = list(map(int,input().split()))
    if query[0] == 0:
        i,x = query[1:]
        seg.apply(i-1,n,(x-arg[i-1])%360)
        arg[i-1] = x
    elif query[0] == 1:
        i,x = query[1:]
        p,q = seg.point_get(i-1)
        l = sqrt(p**2+q**2)
        seg.point_set(i-1,[p*(x/l),q*(x/l)])
    else:
        i = query[1]
        print(*seg.prod(0,i))
0