Subdifferential characterization of quasiconvexity and convexity