結果
問題 | No.1675 Strange Minimum Query |
ユーザー | ansain |
提出日時 | 2021-09-10 21:52:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,913 bytes |
コンパイル時間 | 147 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 123,416 KB |
最終ジャッジ日時 | 2024-06-11 23:36:42 |
合計ジャッジ時間 | 31,666 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,184 KB |
testcase_01 | AC | 41 ms
55,300 KB |
testcase_02 | AC | 42 ms
55,556 KB |
testcase_03 | AC | 875 ms
100,768 KB |
testcase_04 | AC | 716 ms
95,228 KB |
testcase_05 | AC | 172 ms
83,588 KB |
testcase_06 | AC | 993 ms
99,288 KB |
testcase_07 | AC | 1,039 ms
111,188 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 708 ms
112,720 KB |
testcase_14 | AC | 994 ms
123,416 KB |
testcase_15 | AC | 919 ms
115,376 KB |
testcase_16 | AC | 42 ms
55,272 KB |
testcase_17 | AC | 416 ms
84,660 KB |
testcase_18 | AC | 515 ms
86,712 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 1,155 ms
105,620 KB |
testcase_23 | AC | 960 ms
96,944 KB |
testcase_24 | AC | 907 ms
99,736 KB |
testcase_25 | AC | 707 ms
94,600 KB |
testcase_26 | WA | - |
testcase_27 | AC | 932 ms
103,992 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 1,276 ms
102,120 KB |
testcase_32 | AC | 1,586 ms
112,180 KB |
testcase_33 | AC | 1,645 ms
111,936 KB |
testcase_34 | AC | 1,541 ms
111,960 KB |
testcase_35 | AC | 1,430 ms
114,380 KB |
testcase_36 | AC | 1,400 ms
114,440 KB |
ソースコード
import sys from collections import defaultdict, Counter, deque from itertools import permutations, combinations, product, combinations_with_replacement, groupby, accumulate import operator from math import sqrt, gcd, factorial #from math import isqrt, prod, comb #python3.8用(notpypy) #from bisect import bisect_left, bisect_right #from functools import lru_cache, reduce #from heapq import heappush, heappop, heapify, heappushpop, heapreplace #import numpy as np #import networkx as nx #from networkx.utils import UnionFind #from numba import njit, b1, i1, i4, i8, f8 #numba例 @njit(i1(i4[:], i8[:, :]),cache=True) 引数i4配列、i8 2次元配列,戻り値i1 #from scipy.sparse import csr_matrix #from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, NegativeCycleError, maximum_bipartite_matching, maximum_flow, minimum_spanning_tree def input(): return sys.stdin.readline().rstrip() def divceil(n, k): return 1+(n-1)//k # n/kの切り上げを返す def yn(hantei, yes='Yes', no='No'): print(yes if hantei else no) #ライブラリ参照https://atcoder.jp/contests/practice2/submissions/20978786 class LazySegmentTree2: __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator): self.me = monoid_identity self.oe = operator_identity self.fmm = func_monoid_monoid self.fmo = func_monoid_operator self.foo = func_operator_operator self.n = len(monoid_data) self.data = monoid_data * 2 for i in range(self.n-1, 0, -1): self.data[i] = self.fmm(self.data[2*i], self.data[2*i+1]) self.lazy = [self.oe] * (self.n * 2) def replace(self, index, value): index += self.n # propagation for shift in range(index.bit_length()-1, 0, -1): i = index >> shift self.lazy[2*i] = self.foo(self.lazy[2*i], self.lazy[i]) self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i]) self.data[i] = self.fmo(self.data[i], self.lazy[i]) self.lazy[i] = self.oe # update self.data[index] = value self.lazy[index] = self.oe # recalculation i = index while i > 1: i //= 2 self.data[i] = self.fmm( self.fmo(self.data[2*i], self.lazy[2*i]), self.fmo(self.data[2*i+1], self.lazy[2*i+1]) ) self.lazy[i] = self.oe def effect(self, l, r, operator): l += self.n r += self.n # preparing indices indices = [] l0 = (l // (l & -l)) // 2 r0 = (r // (r & -r) - 1) // 2 while r0 > l0: indices.append(r0) r0 //= 2 while l0 > r0: indices.append(l0) l0 //= 2 while l0 and l0 != r0: indices.append(r0) r0 //= 2 if l0 == r0: break indices.append(l0) l0 //= 2 while r0: indices.append(r0) r0 //= 2 # propagation for i in reversed(indices): self.lazy[2*i] = self.foo(self.lazy[2*i], self.lazy[i]) self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i]) self.data[i] = self.fmo(self.data[i], self.lazy[i]) self.lazy[i] = self.oe # effect while l < r: if l % 2: self.lazy[l] = self.foo(self.lazy[l], operator) l += 1 if r % 2: r -= 1 self.lazy[r] = self.foo(self.lazy[r], operator) l //= 2 r //= 2 # recalculation for i in indices: self.data[i] = self.fmm( self.fmo(self.data[2*i], self.lazy[2*i]), self.fmo(self.data[2*i+1], self.lazy[2*i+1]) ) self.lazy[i] = self.oe def folded(self, l, r): l += self.n r += self.n # preparing indices indices = [] l0 = (l // (l & -l)) // 2 r0 = (r // (r & -r) - 1) // 2 while r0 > l0: indices.append(r0) r0 //= 2 while l0 > r0: indices.append(l0) l0 //= 2 while l0 and l0 != r0: indices.append(r0) r0 //= 2 if l0 == r0: break indices.append(l0) l0 //= 2 while r0: indices.append(r0) r0 //= 2 # propagation for i in reversed(indices): self.lazy[2*i] = self.foo(self.lazy[2*i], self.lazy[i]) self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i]) self.data[i] = self.fmo(self.data[i], self.lazy[i]) self.lazy[i] = self.oe # fold left_folded = self.me right_folded = self.me while l < r: if l % 2: left_folded = self.fmm(left_folded, self.fmo(self.data[l], self.lazy[l])) l += 1 if r % 2: r -= 1 right_folded = self.fmm(self.fmo(self.data[r], self.lazy[r]), right_folded) l //= 2 r //= 2 return self.fmm(left_folded, right_folded) def main(): mod = 10**9+7 mod2 = 998244353 n,q=map(int, input().split()) lrb=[list(map(int, input().split())) for i in range(q)] lrb.sort(key=lambda x:x[2]) seg=LazySegmentTree2([10**10]*n,10**10,-1,min,lambda x,y: x if y==-1 else y,lambda x,y: x if y==-1 else y) for l,r,b in lrb: seg.effect(l-1,r,b) for l,r,b in lrb: if seg.folded(l-1,r)!=b: print(-1) return print(*[seg.folded(i,i+1) for i in range(n)]) if __name__ == '__main__': main()