結果

問題 No.1675 Strange Minimum Query
ユーザー terasaterasa
提出日時 2022-06-17 01:29:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,215 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 137,184 KB
最終ジャッジ日時 2024-04-16 15:24:25
合計ジャッジ時間 50,783 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
62,900 KB
testcase_01 AC 45 ms
55,556 KB
testcase_02 AC 44 ms
55,872 KB
testcase_03 AC 1,489 ms
104,544 KB
testcase_04 AC 1,410 ms
102,300 KB
testcase_05 AC 196 ms
83,680 KB
testcase_06 AC 1,747 ms
109,716 KB
testcase_07 AC 1,946 ms
111,028 KB
testcase_08 AC 53 ms
64,504 KB
testcase_09 AC 110 ms
77,228 KB
testcase_10 AC 1,363 ms
108,808 KB
testcase_11 AC 619 ms
96,160 KB
testcase_12 AC 1,522 ms
113,920 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 43 ms
55,400 KB
testcase_17 AC 659 ms
88,396 KB
testcase_18 AC 846 ms
91,168 KB
testcase_19 AC 1,298 ms
106,548 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 1,375 ms
98,784 KB
testcase_26 AC 889 ms
93,296 KB
testcase_27 TLE -
testcase_28 AC 1,214 ms
102,132 KB
testcase_29 AC 1,019 ms
102,864 KB
testcase_30 AC 863 ms
93,464 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