結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー noriocnorioc
提出日時 2024-02-24 01:19:16
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,624 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 67,292 KB
最終ジャッジ日時 2024-09-29 09:39:55
合計ジャッジ時間 4,050 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 2
other RE * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

from atcoder.lazysegtree import LazySegTree


class Compression:
    def __init__(self, iterable):
        self.xs = sorted(set(iterable))
        self.n = len(self.xs)
        self.x2i = {}
        for i, x in enumerate(self.xs):
            self.x2i[x] = i

    def __len__(self):
        return self.n

    def index(self, x):
        """x のインデックスを返す"""
        return self.x2i[x]

    def value(self, index):
        """インデックスに対応する値を返す"""
        return self.xs[index]



# 値データ
S = int
# 遅延データ
F = int


# 値データを合成
def op(a: S, b: S) -> S:
    # 使わない
    return 0


# 遅延データを値データに反映 : f(x)
def mapping(f: F, x: S) -> S:
    if f == 0: return x
    return f


# 遅延データを伝搬
# 二つの遅延データを合成 : (f . g)
def composition(f: F, g: F) -> F:
    if f == 0: return g
    return f


N, A = map(int, input().split())
X = list(map(int, input().split()))

ss = set(X)
T = int(input())
segs = []
for _ in range(T):
    L, R = map(int, input().split())
    segs.append((L, R))
    ss.add(L)
    ss.add(R)

comp = Compression(ss)
# 単位元 e : 全ての a に対して op(a, e) = op(e, a) = a を満たす
# 恒等写像 id : 全ての a に対して mapping(id, a) = a を満たす
lsegt = LazySegTree(
    op=op,
    e=0,
    mapping=mapping,
    composition=composition,
    id_=0,
    v=[-1] * len(comp))

for i, (l, r) in enumerate(segs):
    li = comp.index(l)
    ri = comp.index(r)
    lsegt.apply(li, ri+1, i+1)

ans = [lsegt.get(comp.index(x)) for x in X]
print(*ans, sep='\n')
0