結果

問題 No.1675 Strange Minimum Query
ユーザー terasaterasa
提出日時 2022-06-17 01:29:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,215 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 137,096 KB
最終ジャッジ日時 2024-10-07 12:11:29
合計ジャッジ時間 47,723 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
60,288 KB
testcase_01 AC 45 ms
55,296 KB
testcase_02 AC 46 ms
54,784 KB
testcase_03 AC 1,326 ms
104,320 KB
testcase_04 AC 1,337 ms
102,116 KB
testcase_05 AC 194 ms
83,456 KB
testcase_06 AC 1,639 ms
109,196 KB
testcase_07 AC 1,839 ms
111,056 KB
testcase_08 AC 55 ms
63,232 KB
testcase_09 AC 115 ms
77,184 KB
testcase_10 AC 1,322 ms
108,536 KB
testcase_11 AC 564 ms
95,920 KB
testcase_12 AC 1,424 ms
113,588 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 46 ms
55,296 KB
testcase_17 AC 654 ms
88,064 KB
testcase_18 AC 843 ms
91,520 KB
testcase_19 AC 1,274 ms
107,020 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,856 ms
106,624 KB
testcase_24 AC 1,802 ms
109,696 KB
testcase_25 AC 1,214 ms
98,304 KB
testcase_26 AC 812 ms
92,672 KB
testcase_27 AC 1,836 ms
115,984 KB
testcase_28 AC 1,044 ms
101,932 KB
testcase_29 AC 912 ms
102,568 KB
testcase_30 AC 758 ms
93,568 KB
testcase_31 TLE -
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


class LazySegTree_RUQ:
    def __init__(self, N, func, e):
        self.N = N
        self.func = func
        self.X = [e] * (N << 1)
        self.lazy = [None] * (N << 1)
        self.e = e

    def build(self, seq):
        for i in range(self.N):
            self.X[self.N + i] = seq[i]
        for i in range(self.N)[::-1]:
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def gindex(self, l, r):
        l += self.N
        r += self.N
        lm = l >> (l & -l).bit_length()
        rm = r >> (r & -r).bit_length()
        while r > l:
            if l <= lm:
                yield l
            if r <= rm:
                yield r
            r >>= 1
            l >>= 1
        while l:
            yield l
            l >>= 1

    def propagates(self, *ids):
        for i in ids[::-1]:
            v = self.lazy[i]
            if v is None:
                continue
            self.lazy[i << 1] = v
            self.lazy[i << 1 | 1] = v
            self.X[i << 1] = v
            self.X[i << 1 | 1] = v
            self.lazy[i] = None

    def update(self, L, R, x):
        *ids, = self.gindex(L, R)
        self.propagates(*ids)
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                self.lazy[L] = x
                self.X[L] = x
                L += 1
            if R & 1:
                R -= 1
                self.lazy[R] = x
                self.X[R] = x
            L >>= 1
            R >>= 1
        for i in ids:
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def query(self, L, R):
        *ids, = self.gindex(L, R)
        self.propagates(*ids)
        L += self.N
        R += self.N
        vL = self.e
        vR = self.e
        while L < R:
            if L & 1:
                vL = self.func(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.func(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.func(vL, vR)


N, Q = map(int, input().split())
query = [tuple(map(int, input().split())) for _ in range(Q)]
query.sort(key=lambda x: x[2])

lst = LazySegTree_RUQ(N, min, 10 ** 9)
lst.build([10 ** 9] * N)

for l, r, B in query:
    l -= 1
    lst.update(l, r, B)

for l, r, B in query:
    l -= 1
    m = lst.query(l, r)
    if m != B:
        print(-1)
        exit()
ans = []
for i in range(N):
    ans.append(lst.query(i, i + 1))
print(*ans)
0