結果

問題 No.259 セグメントフィッシング+
ユーザー maspymaspy
提出日時 2020-04-01 01:58:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 907 ms / 2,000 ms
コード長 2,082 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 44,000 KB
最終ジャッジ日時 2023-09-08 00:00:42
合計ジャッジ時間 19,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,084 KB
testcase_01 AC 16 ms
8,128 KB
testcase_02 AC 16 ms
8,096 KB
testcase_03 AC 16 ms
8,164 KB
testcase_04 AC 16 ms
8,080 KB
testcase_05 AC 17 ms
8,164 KB
testcase_06 AC 16 ms
8,048 KB
testcase_07 AC 16 ms
8,168 KB
testcase_08 AC 868 ms
43,856 KB
testcase_09 AC 878 ms
43,864 KB
testcase_10 AC 873 ms
43,860 KB
testcase_11 AC 863 ms
43,852 KB
testcase_12 AC 876 ms
43,820 KB
testcase_13 AC 907 ms
43,928 KB
testcase_14 AC 888 ms
43,900 KB
testcase_15 AC 900 ms
43,896 KB
testcase_16 AC 904 ms
43,964 KB
testcase_17 AC 897 ms
43,856 KB
testcase_18 AC 901 ms
43,864 KB
testcase_19 AC 888 ms
43,896 KB
testcase_20 AC 871 ms
44,000 KB
testcase_21 AC 874 ms
43,984 KB
testcase_22 AC 892 ms
43,936 KB
testcase_23 AC 430 ms
39,672 KB
testcase_24 AC 772 ms
43,864 KB
testcase_25 AC 774 ms
43,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, Q = map(int, readline().split())
X, T, Y, Z = zip(*[line.split() for line in readlines()])
T = map(int, T)
Y = map(int, Y)
Z = map(int, Z)


class BinaryIndexedTree():
    def __init__(self, seq):
        self.size = len(seq)
        self.depth = self.size.bit_length()
        self.build(seq)

    def build(self, seq):
        data = seq
        size = self.size
        for i, x in enumerate(data):
            j = i + (i & (-i))
            if j < size:
                data[j] += data[i]
        self.data = data

    def __repr__(self):
        return self.data.__repr__()

    def get_sum(self, i):
        data = self.data
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        data = self.data
        size = self.size
        while i < size:
            data[i] += x
            i += i & -i

    def find_kth_element(self, k):
        data = self.data
        size = self.size
        x, sx = 0, 0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + data[y]
            if sy < k:
                x, sx = y, sy
        return x + 1


bit = BinaryIndexedTree([0] * (N + N + N + N + 10))
for x, t, y, z in zip(X, T, Y, Z):
    if x == b'L':
        n = N + N - 1 - y
        n -= t
        n %= (N + N)
        bit.add(n + 1, z)
        bit.add(n + N + N + 1, z)
    elif x == b'R':
        n = y - t
        n %= (N + N)
        bit.add(n + 1, z)
        bit.add(n + N + N + 1, z)
    elif x == b'C':
        cnt = 0
        z -= 1
        for y1, z1 in ((y, z), (N + N - 1 - z, N + N - 1 - y)):
            y1 -= t
            z1 -= t
            q = y1 // (N + N)
            y1 -= q * (N + N)
            z1 -= q * (N + N)
            cnt += bit.get_sum(z1 + 1) - bit.get_sum(y1)
        print(cnt)
0