Editorial for Kaninho và bài toán tìm phần tử gần nhất
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Đây là dạng bài toán stack rất cơ bản. Tuy nhiên, điều kiện \(1 \leq a[i] \leq 50\) giúp bài toán dễ hơn rất nhiều. Để giải bài này, chúng ta cần lưu mảng \(last[1..50]\) là vị trí xuất hiện gần nhất của các số 1, 2, ..., 50 trong lúc for từ 1 tới \(n\).
Comments