갑자기 더워진 날씨에 선풍기를 틀고 말았다. 💦 아침에는 좀 쌀쌀하고 낮에는 엄청 덥고, 어느 장단에 맞춰야 할지 아직 고민되는 날씨가 찾아왔다. 덥다 보니 집에 돌아오면 땀 범벅이 돼버린다. 이러면 운동하기가 너무 괴롭다. 4월에 30도라니! 너무한 거 아니냐고~~ 😡
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
Solution s = new Solution();
System.out.println(s.solution(getInput(br), getInput(br)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static int[] getInput(BufferedReader br) throws IOException {
int len = Integer.parseInt(br.readLine());
int[] arr = new int[len];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < len; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
return arr;
}
}
class Solution {
public String solution(int[] arr, int[] targets) {
Arrays.sort(arr);
StringBuilder answer = new StringBuilder();
for (int target : targets) {
int start = getLowerBound(arr, target);
int end = getUpperBound(arr, target);
answer.append(end - start).append(" ");
}
return answer.toString();
}
private int getLowerBound(int[] arr, int target) {
int l = 0;
int r = arr.length;
int mid = 0;
while (l < r) {
mid = (l + r) / 2;
if (arr[mid] < target)
l = mid + 1;
else
r = mid;
}
return r;
}
private int getUpperBound(int[] arr, int target) {
int l = 0;
int r = arr.length;
int mid = 0;
while (l < r) {
mid = (l + r) / 2;
if (arr[mid] <= target) {
l = mid + 1;
} else {
r = mid;
}
}
return r;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
Solution s = new Solution();
System.out.println(s.solve(getInput(br)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static int[] getInput(BufferedReader br) throws IOException {
int len = Integer.parseInt(br.readLine());
int[] arr = new int[len];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
return arr;
}
}
class Solution {
public String solve(int[] arr) {
StringBuilder answer = new StringBuilder();
int[] compressedArray = compress(arr);
for (int i : arr) {
int index = getLowerBound(compressedArray, i);
answer.append(index).append(" ");
}
return answer.toString();
}
private int getLowerBound(int[] arr, int target) {
int lp = 0;
int rp = arr.length;
while(lp < rp) {
int mid = (lp + rp) / 2;
if (arr[mid] < target) {
lp = mid + 1;
} else {
rp = mid;
}
}
return rp;
}
private int[] compress(int[] arr) {
TreeSet<Integer> set = new TreeSet<>();
for (int i : arr) {
set.add(i);
}
int[] result = new int[set.size()];
int idx = 0;
for (Integer i : set) {
result[idx++] = i;
}
return result;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
Solution s = new Solution();
System.out.println(s.solution(getInput(br)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static int[] getInput(BufferedReader br) throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int len = Integer.parseInt(st.nextToken());
int colors = Integer.parseInt(st.nextToken());
int[] arr = new int[len];
st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
return arr;
}
}
class Solution {
public int solution(int[] arr) {
int maxLen = 0;
int curColor = -1;
int curLen = 1;
for (int i = 0; i < arr.length; i++) {
int nextColor = arr[i];
if (curColor == nextColor) {
curLen = 1;
}
maxLen = Math.max(maxLen, curLen++);
curColor = nextColor;
}
return maxLen;
}
}