暴力大法好,对于输入的区间$[A,B]$,直接把$[A+1,B-1]$之间的所有值减1
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int[] arr = new int[n + 1];
int p = cin.nextInt();
int h = cin.nextInt();
Arrays.fill(arr, h);
int m = cin.nextInt();
Set<String> set = new HashSet<String>();
int[] op = new int[2];
for (int i = 0; i < m; i++) {
op[0] = cin.nextInt(); // A
op[1] = cin.nextInt(); // B
Arrays.sort(op);
if (!set.contains(op[0] + "" + op[1])) {
set.add(op[0] + "" + op[1]);
for (int c = op[0] + 1; c < op[1]; c++)
arr[c]--;
}
}
for (int i = 1; i <= n; i++)
System.out.println(arr[i]);
}
}
同暴力AC此题- -…