結果
| 問題 | No.3327 うるせぇ、ポリオミノぶつけんぞ |
| コンテスト | |
| ユーザー |
tokugh
|
| 提出日時 | 2025-11-01 16:36:37 |
| 言語 | Julia (2.11.2) |
| 結果 |
AC
|
| 実行時間 | 1,550 ms / 3,000 ms |
| コード長 | 2,339 bytes |
| コンパイル時間 | 400 ms |
| コンパイル使用メモリ | 7,972 KB |
| 実行使用メモリ | 291,368 KB |
| 最終ジャッジ日時 | 2025-11-01 16:37:17 |
| 合計ジャッジ時間 | 36,238 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 |
ソースコード
toI(s=readline()) = parse(Int,s)
toVI(s=readline()) = map(toI,eachsplit(s))
rep(f,n) = [f() for _ in 1:n]
@enum YN Yes=1 No=0
function main()
n,q = toVI()
a = toVI()
queries = rep(toVI,q)
solve(n,q,a,queries) .|> println
end
function solve(n,q,a,queries)
st = SegTree(max,0,a)
res = fill(-1,q)
for (i,(c,x)) in pairs(queries)
reduce(st,1,n) > x || continue
if c == 1
ok = 0; ng = n+1
while ng-ok > 1
m = (ok+ng)÷2
if reduce(st,1,m) ≤ x
ok = m
else
ng = m
end
end
# if 1 ≤ ok+1 ≤ n
res[i] = ok+1
st[ok+1] = 0
# end
elseif c == 2
ng = 0; ok = n+1
while ok-ng > 1
m = (ok+ng)÷2
if reduce(st,m,n) ≤ x
ok = m
else
ng = m
end
end
# if 1 ≤ ok-1 ≤ n
res[i] = ok-1
st[ok-1] = 0
# end
end
# @info i,st
end
res
end
struct SegTree{T,⊗}
e::T
n::Int
node::Vector{T}
function SegTree(⊗,e,n,T=typeof(e))
node = [e for _ in 1:2n-1]
new{T,⊗}(e,n,node)
end
function SegTree(⊗,e,xs::AbstractVector,T=eltype(xs))
n = length(xs)
node = Vector{T}(undef,2n-1)
node[n:end] .= xs
for i ∈ n-1:-1:1
node[i] = node[2i] ⊗ node[2i+1]
end
new{T,⊗}(e,n,node)
end
end
function Base.setindex!((;n,node)::SegTree{T,⊗},x,i) where {T,⊗}
i += n-1
node[i] = x
while i > 1
i >>= 1
node[i] = node[2i] ⊗ node[2i+1]
end
return x
end
function Base.getindex((;n,node)::SegTree{T,⊗},i) where {T,⊗}
i += n-1
x = node[i]
return x
end
function Base.reduce((;e,n,node)::SegTree{T,⊗},l::Int,r::Int) where {T,⊗}
l += n-1; r += n-1
sml = e; smr = e
while l ≤ r
isodd(l) && (sml = sml ⊗ node[l])
iseven(r) && (smr = node[r] ⊗ smr)
l = (l+1) >> 1
r = (r+1) >> 1 - 1
end
return sml ⊗ smr
end
function Base.reduce(a::SegTree)
(;n) = a
reduce(a,1,n)
end
main()
tokugh