AcWing 736. 安迪种树
原题链接
简单
作者:
小辉_9
,
2020-08-26 12:15:53
,
所有人可见
,
阅读 498
差分
Java 代码
import java.util.*;
public class Main {
public static int N = (int)1e6;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int q = in.nextInt();
int[] s = new int[N];
for (int i = 0; i < q; i++) {
int l = in.nextInt();
int r = in.nextInt();
s[l]++;
s[r+1]--;
}
for (int i = 1; i <= n; i++) {
s[i] += s[i-1];
}
for (int i = 1; i <= n; i++) {
System.out.print(s[i] + " ");
}
}
}