Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active December 24, 2015 12:09
Show Gist options
  • Select an option

  • Save cocodrips/6796003 to your computer and use it in GitHub Desktop.

Select an option

Save cocodrips/6796003 to your computer and use it in GitHub Desktop.
SRM586 Div2 500
public class PiecewiseLinearFunctionDiv2 {
public int[] countSolutions(int[] Y, int[] query) {
int[] ans = new int[query.length];
for (int q = 0; q < query.length; q++) {
int n = 0;
if (query[q] == Y[Y.length-1]) {
n++;
}
for (int y = 0; y < Y.length-1; y++) {
if (Y[y] == query[q] && Y[y+1] == query[q]) {
n = -1;
break;
}
if ((Y[y] <= query[q] && query[q] < Y[y+1]) ||
(Y[y] >= query[q] && query[q] > Y[y+1])) {
n++;
}
}
ans[q] = n;
}
return ans;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment