結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー gew1fw
提出日時 2025-06-12 14:48:29
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,306 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,656 KB
実行使用メモリ 303,468 KB
最終ジャッジ日時 2025-06-12 14:52:12
合計ジャッジ時間 23,192 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other MLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    ptr = 0
    N = int(data[ptr])
    ptr += 1
    Q = int(data[ptr])
    ptr += 1

    queries = []
    for _ in range(Q):
        x = int(data[ptr])
        l = int(data[ptr+1])
        r = int(data[ptr+2])
        queries.append((x, l, r))
        ptr +=3

    intervals = []
    intervals.append((0, N-1, -1, 0))

    bonuses = [0] * 5

    for q in queries:
        x, l, r = q
        if x == 0:
            sums = [0] * 5
            for interval in intervals:
                s, e, t, d = interval
                if s > r or e < l:
                    continue
                overlap_start = max(s, l)
                overlap_end = min(e, r)
                if overlap_start > overlap_end:
                    continue
                overlap_length = overlap_end - overlap_start + 1
                if t != -1:
                    sums[t] += overlap_length * d
            max_sum = max(sums)
            count = sums.count(max_sum)
            if count == 1:
                idx = sums.index(max_sum)
                bonuses[idx] += max_sum
        else:
            team = x - 1
            new_intervals = []
            for interval in intervals:
                s, e, t, d = interval
                if e < l or s > r:
                    new_intervals.append(interval)
                    continue
                if s < l:
                    new_intervals.append((s, l-1, t, d))
                part_start = max(s, l)
                part_end = min(e, r)
                if part_start <= part_end:
                    if t == team:
                        new_d = d + 1
                    else:
                        new_d = 1
                    new_intervals.append((part_start, part_end, team, new_d))
                if e > r:
                    new_intervals.append((r+1, e, t, d))
            intervals = new_intervals

    team_scores = [0] * 5
    for interval in intervals:
        s, e, t, d = interval
        if t != -1:
            length = e - s + 1
            team_scores[t] += length * d
    for i in range(5):
        team_scores[i] += bonuses[i]
        team_scores[i] %= (10**18 + 9)

    print(' '.join(map(str, team_scores)))

if __name__ == '__main__':
    main()
0