An optimal frequency-domain finite-difference operator with a flexible stencil and its application in discontinuous-grid modeling