結果

問題 No.675 ドットちゃんたち
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-11 15:47:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,898 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 81,884 KB
実行使用メモリ 81,552 KB
最終ジャッジ日時 2024-05-01 06:49:24
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,940 KB
testcase_01 AC 40 ms
54,352 KB
testcase_02 AC 35 ms
53,028 KB
testcase_03 AC 36 ms
53,912 KB
testcase_04 AC 37 ms
52,460 KB
testcase_05 AC 201 ms
81,112 KB
testcase_06 AC 209 ms
79,716 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class fenwick_tree(object):
    def __init__(self, n):
        self.n = n
        self.log = n.bit_length()
        self.data = [0] * n

    def __sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def add(self, p, x):
        """ a[p] += xを行う"""
        p += 1
        while p <= self.n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        """a[l] + a[l+1] + .. + a[r-1]を返す"""
        return self.__sum(r) - self.__sum(l)

    def lower_bound(self, x):
        """a[0] + a[1] + .. a[i] >= x となる最小のiを返す"""
        if x <= 0:
            return -1
        i = 0
        k = 1 << self.log
        while k:
            if i + k <= self.n and self.data[i + k - 1] < x:
                x -= self.data[i + k - 1]
                i += k
            k >>= 1
        return i


def convert(x, y, rot):
    if rot % 4 == 0:
        return x, y
    if rot % 4 == 1:
        return -y, x
    if rot % 4 == 2:
        return -x, -y
    return y, -x


N, px, py = map(int, input().split())
x = fenwick_tree(N)
y = fenwick_tree(N)
rot = fenwick_tree(N)


cnt = 0
for i in reversed(range(N)):
    flag, *arg = map(int, input().split())
    if flag == 3:
        rot.add(i, 1)
        cnt += 1
        continue
    if flag == 1:
        dx, dy = convert(arg[0], 0, cnt)
    else:
        dx, dy = convert(0, arg[0], cnt)
    x.add(i, dx)
    y.add(i, dy)


for i in reversed(range(N)):
    dx = x.sum(0, i+1)
    dy = y.sum(0, i+1)
    roll = rot.sum(0, i+1)

    ansx = px + dx
    ansy = py + dy
    if roll % 4 == 1:
        ansx, ansy = ansy, -ansx
    elif roll % 4 == 2:
        ansx, ansy = -ansx, -ansy
    elif roll % 4 == 3:
        ansx, ansy = -ansy, ansx
    print(ansx, ansy)
0