답안 #590103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590103 2022-07-05T14:17:44 Z DylanSmith Global Warming (CEOI18_glo) Java 11
100 / 100
610 ms 25792 KB
import java.util.*;
import java.io.*;
public class glo {
    public static void main(String[] args) throws IOException {
        Reader in = new Reader();
        PrintWriter out = new PrintWriter(System.out);
        
        int N = in.nextInt(), K = in.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = in.nextInt();
        }
        List<Integer> compress = new ArrayList<>();
        for (int i : arr) {
            compress.add(i);
        }
        Collections.sort(compress);
        for (int i = 0; i < N; i++) {
            arr[i] = Collections.binarySearch(compress, arr[i]);
        }
        int[] up = new int[compress.size()];
        int index = 0;
        for (int i = 0; i < compress.size(); i++) {
            while (index + 1 < compress.size() && compress.get(index + 1) < compress.get(i) + K) {
                index++;
            }
            up[i] = index;
        }
        int M = 1;
        while (M < compress.size()) {
            M <<= 1;
        }
        int[] tree = new int[M * 2], tree2 = new int[M * 2];
        for (int i : arr) {
            int l = M, r = i - 1 + M;
            int max = 0, max2 = 0;
            while (l <= r) {
                if (l % 2 == 1) {
                    max = Math.max(max, tree[l]);
                    max2 = Math.max(max2, tree2[l]);
                    l >>= 1;
                    l++;
                } else {
                    l >>= 1;
                }
                if (r % 2 == 0) {
                    max = Math.max(max, tree[r]);
                    max2 = Math.max(max2, tree2[r]);
                    r >>= 1;
                    r--;
                } else {
                    r >>= 1;
                }
            }
            l = M;
            r = up[i] + M;
            while (l <= r) {
                if (l % 2 == 1) {
                    max2 = Math.max(max2, tree[l]);
                    l >>= 1;
                    l++;
                } else {
                    l >>= 1;
                }
                if (r % 2 == 0) {
                    max2 = Math.max(max2, tree[r]);
                    r >>= 1;
                    r--;
                } else {
                    r >>= 1;
                }
            }
            max++;
            max2++;
            int current = i + M;
            while (current > 0) {
                tree[current] = Math.max(tree[current], max);
                tree2[current] = Math.max(tree2[current], max2);
                current >>= 1;
            }
        }
        out.println(tree2[1]);
        
        out.close();
    }
    static class Reader {
        BufferedInputStream in;
        public Reader() {
            in = new BufferedInputStream(System.in);
        }
        public String nextLine() throws IOException {
            int c;
            StringBuilder sb = new StringBuilder("");
            while ((c = in.read()) != '\n')
                sb.append((char)(c));
            return sb.toString();
        }
        public String next() throws IOException {
            int c;
            StringBuilder sb = new StringBuilder("");
            while ((c = in.read()) != ' ' && c != '\n')
                sb.append((char)(c));
            return sb.toString();
        }
        public int nextInt() throws IOException {
            return (int)nextLong();
        }
        public long nextLong() throws IOException {
            int c;
            long res = 0;
            boolean start = false, negative = false;
            while ((c = in.read()) != ' ' && c != '\n' || !start)
                if (c >= '0' && c <= '9' || c == '-') {
                    start = true;
                    if (c == '-')
                        negative = true;
                    else
                        res = res * 10 + c - '0';
                }
            return res * (negative ? -1 : 1);
        }
    }
    public static void sort(int[] arr) {
        List<Integer> list = new ArrayList<>();
        for (int i : arr) {
            list.add(i);
        }
        Collections.sort(list);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = list.get(i);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 8632 KB Output is correct
2 Correct 54 ms 8212 KB Output is correct
3 Correct 60 ms 8236 KB Output is correct
4 Correct 62 ms 8200 KB Output is correct
5 Correct 64 ms 8388 KB Output is correct
6 Correct 68 ms 8296 KB Output is correct
7 Correct 56 ms 8292 KB Output is correct
8 Correct 61 ms 8352 KB Output is correct
9 Correct 52 ms 8280 KB Output is correct
10 Correct 55 ms 8444 KB Output is correct
11 Correct 60 ms 8240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 8632 KB Output is correct
2 Correct 54 ms 8212 KB Output is correct
3 Correct 60 ms 8236 KB Output is correct
4 Correct 62 ms 8200 KB Output is correct
5 Correct 64 ms 8388 KB Output is correct
6 Correct 68 ms 8296 KB Output is correct
7 Correct 56 ms 8292 KB Output is correct
8 Correct 61 ms 8352 KB Output is correct
9 Correct 52 ms 8280 KB Output is correct
10 Correct 55 ms 8444 KB Output is correct
11 Correct 60 ms 8240 KB Output is correct
12 Correct 61 ms 8324 KB Output is correct
13 Correct 63 ms 8164 KB Output is correct
14 Correct 57 ms 8492 KB Output is correct
15 Correct 60 ms 8380 KB Output is correct
16 Correct 64 ms 8160 KB Output is correct
17 Correct 63 ms 8236 KB Output is correct
18 Correct 60 ms 8352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 8632 KB Output is correct
2 Correct 54 ms 8212 KB Output is correct
3 Correct 60 ms 8236 KB Output is correct
4 Correct 62 ms 8200 KB Output is correct
5 Correct 64 ms 8388 KB Output is correct
6 Correct 68 ms 8296 KB Output is correct
7 Correct 56 ms 8292 KB Output is correct
8 Correct 61 ms 8352 KB Output is correct
9 Correct 52 ms 8280 KB Output is correct
10 Correct 55 ms 8444 KB Output is correct
11 Correct 60 ms 8240 KB Output is correct
12 Correct 61 ms 8324 KB Output is correct
13 Correct 63 ms 8164 KB Output is correct
14 Correct 57 ms 8492 KB Output is correct
15 Correct 60 ms 8380 KB Output is correct
16 Correct 64 ms 8160 KB Output is correct
17 Correct 63 ms 8236 KB Output is correct
18 Correct 60 ms 8352 KB Output is correct
19 Correct 80 ms 8492 KB Output is correct
20 Correct 79 ms 8492 KB Output is correct
21 Correct 87 ms 8360 KB Output is correct
22 Correct 91 ms 8640 KB Output is correct
23 Correct 74 ms 8484 KB Output is correct
24 Correct 75 ms 8448 KB Output is correct
25 Correct 73 ms 8412 KB Output is correct
26 Correct 77 ms 8336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 610 ms 25384 KB Output is correct
2 Correct 533 ms 25604 KB Output is correct
3 Correct 545 ms 25744 KB Output is correct
4 Correct 576 ms 25792 KB Output is correct
5 Correct 304 ms 21876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 15108 KB Output is correct
2 Correct 298 ms 15240 KB Output is correct
3 Correct 293 ms 15500 KB Output is correct
4 Correct 203 ms 12788 KB Output is correct
5 Correct 56 ms 8340 KB Output is correct
6 Correct 191 ms 14484 KB Output is correct
7 Correct 308 ms 15344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 404 ms 19388 KB Output is correct
2 Correct 389 ms 18412 KB Output is correct
3 Correct 520 ms 25728 KB Output is correct
4 Correct 313 ms 21900 KB Output is correct
5 Correct 235 ms 16852 KB Output is correct
6 Correct 266 ms 22080 KB Output is correct
7 Correct 268 ms 22276 KB Output is correct
8 Correct 451 ms 19120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 8632 KB Output is correct
2 Correct 54 ms 8212 KB Output is correct
3 Correct 60 ms 8236 KB Output is correct
4 Correct 62 ms 8200 KB Output is correct
5 Correct 64 ms 8388 KB Output is correct
6 Correct 68 ms 8296 KB Output is correct
7 Correct 56 ms 8292 KB Output is correct
8 Correct 61 ms 8352 KB Output is correct
9 Correct 52 ms 8280 KB Output is correct
10 Correct 55 ms 8444 KB Output is correct
11 Correct 60 ms 8240 KB Output is correct
12 Correct 61 ms 8324 KB Output is correct
13 Correct 63 ms 8164 KB Output is correct
14 Correct 57 ms 8492 KB Output is correct
15 Correct 60 ms 8380 KB Output is correct
16 Correct 64 ms 8160 KB Output is correct
17 Correct 63 ms 8236 KB Output is correct
18 Correct 60 ms 8352 KB Output is correct
19 Correct 80 ms 8492 KB Output is correct
20 Correct 79 ms 8492 KB Output is correct
21 Correct 87 ms 8360 KB Output is correct
22 Correct 91 ms 8640 KB Output is correct
23 Correct 74 ms 8484 KB Output is correct
24 Correct 75 ms 8448 KB Output is correct
25 Correct 73 ms 8412 KB Output is correct
26 Correct 77 ms 8336 KB Output is correct
27 Correct 610 ms 25384 KB Output is correct
28 Correct 533 ms 25604 KB Output is correct
29 Correct 545 ms 25744 KB Output is correct
30 Correct 576 ms 25792 KB Output is correct
31 Correct 304 ms 21876 KB Output is correct
32 Correct 343 ms 15108 KB Output is correct
33 Correct 298 ms 15240 KB Output is correct
34 Correct 293 ms 15500 KB Output is correct
35 Correct 203 ms 12788 KB Output is correct
36 Correct 56 ms 8340 KB Output is correct
37 Correct 191 ms 14484 KB Output is correct
38 Correct 308 ms 15344 KB Output is correct
39 Correct 404 ms 19388 KB Output is correct
40 Correct 389 ms 18412 KB Output is correct
41 Correct 520 ms 25728 KB Output is correct
42 Correct 313 ms 21900 KB Output is correct
43 Correct 235 ms 16852 KB Output is correct
44 Correct 266 ms 22080 KB Output is correct
45 Correct 268 ms 22276 KB Output is correct
46 Correct 451 ms 19120 KB Output is correct
47 Correct 429 ms 19112 KB Output is correct
48 Correct 368 ms 18884 KB Output is correct
49 Correct 590 ms 25592 KB Output is correct
50 Correct 311 ms 22564 KB Output is correct
51 Correct 260 ms 20084 KB Output is correct
52 Correct 301 ms 23372 KB Output is correct
53 Correct 263 ms 21704 KB Output is correct
54 Correct 273 ms 22784 KB Output is correct
55 Correct 477 ms 25432 KB Output is correct