Editorial for Số bạn bè


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.

Authors: khactrung1912

Ta sẽ làm riêng lẻ \(2\) subtask:

  • Subtask \(1\): \(a_i \leq 10^9\)
  • Subtask \(2\): \(a_i \leq 10^6\)
Subtask 1

Ta sẽ sắp xếp lại dãy theo thứ tự tăng dần, sau đó duyệt qua từng phần tử, nếu \(a_i=a_{i-1}\) thì ta sẽ tăng biến kết quả lên.
Lưu ý trường hợp bị cộng lặp( VD : \(1\) \(3\) \(3\) \(3\))
Độ phức tạp : \(O(Nlog(N))\)

Subtask 2

Đánh dấu số lần xuất hiện của từng phần tử sau đó duyệt \(\sum_{i=1}^n\) nếu \(dp_i \geq 2\) thì ta sẽ tăng biến kết quả.
Độ phức tạp \(O(N)\)



Comments

There are no comments at the moment.