-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSolution.java
43 lines (35 loc) Β· 1.32 KB
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package TimeComplexity.swea3307;
import java.io.*;
import java.util.*;
public class Solution {
static int T, N;
static int[] L;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/TimeComplexity/swea3307/sample_input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
N = Integer.parseInt(br.readLine());
L = new int[N];
int last = 0;
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
int n = Integer.parseInt(st.nextToken());
if (i == 0) L[0] = n;
if (L[last] < n) L[++last] = n;
else {
int start = 0, end = last;
while (start < end) {
int mid = (start + end) / 2;
if (L[mid] < n) start = mid+1;
else end = mid;
}
L[end] = n;
}
}
sb.append("#").append(t).append(" ").append(++last).append("\n");
}
System.out.println(sb.toString());
}
}