More and more lines are using the Communication Based Train Control (CBTC) systems in urban rail transit. Trains are operated by tracking a pre-determined target speed curve in the CBTC system, so one of the most effective ways of reducing energy consumption is to fully understand the optimum curves that should prevail under varying operating conditions. Additionally, target speed curves need to be calculated with optimum real-time performance in order to cope with changed interstation planning running time. Therefore, this paper proposes a fast and effective algorithm for optimization, based on a two-stage method to find the optimal curve using a max-min ant colony optimization system, using approximate calculations of a discrete combination optimization model. The first stage unequally discretizes the line based on static gradient and speed limit in low-density and it could conduct a comprehensive search for viable energy saving target speed curves. The second stage unequally discretizes the line based on first stage discretion results, it makes full use of first-stage optimization information as pheromone, quickly optimizing the results to satisfy real-time demands. The algorithm is improved through consideration of the experience of train drivers. Finally, the paper presents some examples based on the operation data of Beijing Changping Subway Line, which is using CBTC system. The simulation results show that the proposed approach presents good energy-efficient and real-time performance.