1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| List<Integer> distinctSorterAlls = alls.stream().distinct().sorted().collect(Collectors.toList());
int index = Collections.binarySearch(distinctSorterAlls, item[0]) + 1; a[index] += item[1]; }
for (int i = 0; i < distinctSorterAlls.size(); i++) { s[i + 1] = s[i] + a[i]; }
int l = Collections.binarySearch(distinctSorterAlls, item[0]) + 1; int r = Collections.binarySearch(distinctSorterAlls, item[1]) + 1; System.out.println(s[r + 1] - s[l]); }
|