結果
| 問題 |
No.1675 Strange Minimum Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-10-16 18:02:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,942 bytes |
| コンパイル時間 | 170 ms |
| コンパイル使用メモリ | 82,648 KB |
| 実行使用メモリ | 149,052 KB |
| 最終ジャッジ日時 | 2024-09-17 19:29:23 |
| 合計ジャッジ時間 | 26,816 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 20 |
ソースコード
#!/usr/bin/env python3
# from typing import *
import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq
def input():
return sys.stdin.readline()[:-1]
# sys.setrecursionlimit(1000000)
# _INPUT = """5 3
# 1 3 1
# 3 5 3
# 4 5 4
# """
# sys.stdin = io.StringIO(_INPUT)
INF = 10**10
class SegTree_Update_QRMin:
def __init__(self, a) -> None:
n = len(a)
self.n0 = 1 << (n-1).bit_length()
self.data = ([INF] * self.n0) + a + ([INF] * (self.n0-n))
for i in reversed(range(1, self.n0)):
self.data[i] = min(self.data[i*2], self.data[i*2+1])
def query_rmin(self, l, r):
l += self.n0
r += self.n0
s = INF
while l < r:
if l & 1:
s = min(s, self.data[l])
l += 1
if r & 1:
s = min(s, self.data[r-1])
r -= 1
l >>= 1
r >>= 1
return s
def update(self, i, x):
i += self.n0
self.data[i] = x
while i > 0:
i >>= 1
self.data[i] = min(self.data[i*2], self.data[i*2+1])
def get_value(self, i) -> int:
return self.data[i+self.n0]
def solve(N, Q, Query):
Query.sort()
hq = []
result = [10**9] * N
k = 0
for i in range(N):
while k < Q and Query[k][0] == i:
l, r, a = Query[k]
k += 1
heapq.heappush(hq, (r, l, a))
if hq:
r, l, a = heapq.heappop(hq)
if r < i:
return [-1]
result[i] = a
seg_tree = SegTree_Update_QRMin(result)
for l, r, a in Query:
if seg_tree.query_rmin(l, r+1) != a:
return [-1]
return result
N, Q = map(int, input().split())
Query = []
for _ in range(Q):
l, r, a = map(int, input().split())
Query.append((l-1, r-1, a))
print(*solve(N, Q, Query))