Editorial for Nhanh Tay Lẹ Mắ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.
  • Subtask \(1\): Duyệt trâu, kiểm tra với mọi cặp \((i,j)\) xem \(a_{i}\) có bằng \(a_{j}\) không. Nếu có thì đây là một cặp thỏa mãn.

  • Subtask \(2\): Đếm tần số xuất hiện của từng số trong mảng. Để tối ưu, ta cần sort lại mảng, khi đó mảng tăng dần, ta thực hiện đếm các số giống nhau liên tiếp nhau là xong. Giả sử có \(k\) số có giá trị là \(x\), thì số cặp có giá trị là \(x\) bằng \(k \times (k-1) / 2\).



Comments

There are no comments at the moment.