# 2158. Amount of New Area Painted Each Day ###### tags: `Leetcode` `Hard` `Merge Interval` Link: https://leetcode.com/problems/amount-of-new-area-painted-each-day/ ## 思路 思路[参考](https://leetcode.com/problems/amount-of-new-area-painted-each-day/discuss/1751389/Jump-Line) compress path的概念 For a day ```i```, try painting all areas in the range. - If the area is empty, set the value on the number line to ```end_i```, and increment the amount painted on that day. - If the area has been painted previously, jump to the end of the painted range (which was recorded on the number line on a previous day). ## Code ```java= class Solution { public int[] amountPainted(int[][] paint) { int[] line = new int[50001]; int n = paint.length; int[] ans = new int[n]; for(int i=0; i<n; i++){ int start = paint[i][0]; int end = paint[i][1]; int p = 0; while(start<end){ int jump = Math.max(start+1, line[start]); if(line[start]==0) ans[i]++; line[start] = Math.max(end, line[start]); start = jump; } } return ans; } } ```