Editorial for HSG 9 Quảng Trị - Tìm trên bảng số


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: i_loveNgocTram

Hãy gọi giá trị chúng ta cần tìm là w:
Dễ thấy 1\le w\le n^2+m^2, khi đó ta chỉ cần điếm số lượng cặp số (i,j) sao cho i\le n,j\le mi^2+j^2\le w, chú ý rằng ở đây (i,j) sẽ khác với (j,i) nếu i khác j. Do đó ta dùng chặt nhị phân để tìm w, nếu số lượng cặp lớn hơn x thì giảm chặt, ngược lại tăng.
Dễ thấy độ phức tạp sẽ là O(t.n.log(n^2+m^2)),



Comments

There are no comments at the moment.