Submission #525672

# Submission time Handle Problem Language Result Execution time Memory
525672 2022-02-12T13:08:40 Z Longgggggggg Rabbit Carrot (LMIO19_triusis) Java 11
100 / 100
204 ms 19532 KB
import java.io.*;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.function.Predicate;

public class triusis {
    public static void main(String[] args) {
        FastIO io = new FastIO();
        int n = io.nextInt();
        int m = io.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 1; i <= n; i++) arr[i] = -(io.nextInt() - i * m);
        ArrayList<Integer> l = new ArrayList<>();
        l.add(0);
        for (int i = 1; i <= n; i++) {
            int val = arr[i];
            int upper = firstTrue(0, l.size() - 1, (x) -> l.get(x) > val);
            if (upper == 0) continue;
            if (upper == l.size()) l.add(val);
            l.set(upper, val);
        }
        io.println(n - l.size() + 1);
        io.close();
    }

    public static int firstTrue(int lo, int hi, Predicate<Integer> test) {
        hi++;
        while (lo < hi) {
            int mid = lo + (hi - lo) / 2;
            if (test.test(mid)) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        return lo;
    }

    private static class FastIO extends PrintWriter {
        private final InputStream stream;
        private final byte[] buf = new byte[1 << 16];
        private int curChar, numChars;

        // standard input
        public FastIO() {
            this(System.in, System.out);
        }

        public FastIO(InputStream i, OutputStream o) {
            super(o);
            stream = i;
        }

        // file input
        public FastIO(String i, String o) throws IOException {
            super(new FileWriter(o));
            stream = new FileInputStream(i);
        }

        // throws InputMismatchException() if previously detected end of file
        private int nextByte() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars == -1) return -1; // end of file
            }
            return buf[curChar++];
        }

        // to read in entire lines, replace c <= ' '
        // with a function that checks whether c is a line break
        public String next() {
            int c;
            do {
                c = nextByte();
            } while (c <= ' ');
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = nextByte();
            } while (c > ' ');
            return res.toString();
        }

        public int nextInt() { // nextLong() would be implemented similarly
            int c;
            do {
                c = nextByte();
            } while (c <= ' ');
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = nextByte();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res = 10 * res + c - '0';
                c = nextByte();
            } while (c > ' ');
            return res * sgn;
        }

        public long nextLong() { // nextLong() would be implemented similarly
            int c;
            do {
                c = nextByte();
            } while (c <= ' ');
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = nextByte();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res = 10 * res + c - '0';
                c = nextByte();
            } while (c > ' ');
            return res * sgn;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8940 KB Output is correct
2 Correct 63 ms 8764 KB Output is correct
3 Correct 67 ms 8908 KB Output is correct
4 Correct 66 ms 9028 KB Output is correct
5 Correct 69 ms 8624 KB Output is correct
6 Correct 69 ms 8960 KB Output is correct
7 Correct 63 ms 8920 KB Output is correct
8 Correct 73 ms 8836 KB Output is correct
9 Correct 67 ms 8848 KB Output is correct
10 Correct 74 ms 8992 KB Output is correct
11 Correct 65 ms 8764 KB Output is correct
12 Correct 66 ms 8864 KB Output is correct
13 Correct 63 ms 8860 KB Output is correct
14 Correct 67 ms 8692 KB Output is correct
15 Correct 64 ms 8948 KB Output is correct
16 Correct 64 ms 9020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8940 KB Output is correct
2 Correct 63 ms 8764 KB Output is correct
3 Correct 67 ms 8908 KB Output is correct
4 Correct 66 ms 9028 KB Output is correct
5 Correct 69 ms 8624 KB Output is correct
6 Correct 69 ms 8960 KB Output is correct
7 Correct 63 ms 8920 KB Output is correct
8 Correct 73 ms 8836 KB Output is correct
9 Correct 67 ms 8848 KB Output is correct
10 Correct 74 ms 8992 KB Output is correct
11 Correct 65 ms 8764 KB Output is correct
12 Correct 66 ms 8864 KB Output is correct
13 Correct 63 ms 8860 KB Output is correct
14 Correct 67 ms 8692 KB Output is correct
15 Correct 64 ms 8948 KB Output is correct
16 Correct 64 ms 9020 KB Output is correct
17 Correct 65 ms 8572 KB Output is correct
18 Correct 65 ms 8932 KB Output is correct
19 Correct 64 ms 8884 KB Output is correct
20 Correct 95 ms 9808 KB Output is correct
21 Correct 96 ms 9660 KB Output is correct
22 Correct 82 ms 9224 KB Output is correct
23 Correct 95 ms 9764 KB Output is correct
24 Correct 97 ms 9916 KB Output is correct
25 Correct 94 ms 9836 KB Output is correct
26 Correct 92 ms 9804 KB Output is correct
27 Correct 100 ms 10208 KB Output is correct
28 Correct 96 ms 10092 KB Output is correct
29 Correct 90 ms 9924 KB Output is correct
30 Correct 98 ms 9868 KB Output is correct
31 Correct 110 ms 10092 KB Output is correct
32 Correct 103 ms 9740 KB Output is correct
33 Correct 99 ms 9508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 8572 KB Output is correct
2 Correct 65 ms 8932 KB Output is correct
3 Correct 64 ms 8884 KB Output is correct
4 Correct 95 ms 9808 KB Output is correct
5 Correct 96 ms 9660 KB Output is correct
6 Correct 82 ms 9224 KB Output is correct
7 Correct 95 ms 9764 KB Output is correct
8 Correct 97 ms 9916 KB Output is correct
9 Correct 94 ms 9836 KB Output is correct
10 Correct 92 ms 9804 KB Output is correct
11 Correct 100 ms 10208 KB Output is correct
12 Correct 96 ms 10092 KB Output is correct
13 Correct 90 ms 9924 KB Output is correct
14 Correct 98 ms 9868 KB Output is correct
15 Correct 110 ms 10092 KB Output is correct
16 Correct 103 ms 9740 KB Output is correct
17 Correct 99 ms 9508 KB Output is correct
18 Correct 64 ms 8940 KB Output is correct
19 Correct 63 ms 8764 KB Output is correct
20 Correct 67 ms 8908 KB Output is correct
21 Correct 66 ms 9028 KB Output is correct
22 Correct 69 ms 8624 KB Output is correct
23 Correct 69 ms 8960 KB Output is correct
24 Correct 63 ms 8920 KB Output is correct
25 Correct 73 ms 8836 KB Output is correct
26 Correct 67 ms 8848 KB Output is correct
27 Correct 74 ms 8992 KB Output is correct
28 Correct 65 ms 8764 KB Output is correct
29 Correct 66 ms 8864 KB Output is correct
30 Correct 63 ms 8860 KB Output is correct
31 Correct 67 ms 8692 KB Output is correct
32 Correct 64 ms 8948 KB Output is correct
33 Correct 64 ms 9020 KB Output is correct
34 Correct 81 ms 9200 KB Output is correct
35 Correct 89 ms 9376 KB Output is correct
36 Correct 89 ms 9456 KB Output is correct
37 Correct 97 ms 9908 KB Output is correct
38 Correct 97 ms 9808 KB Output is correct
39 Correct 98 ms 10456 KB Output is correct
40 Correct 115 ms 10356 KB Output is correct
41 Correct 81 ms 9256 KB Output is correct
42 Correct 101 ms 9464 KB Output is correct
43 Correct 95 ms 9696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 9200 KB Output is correct
2 Correct 89 ms 9376 KB Output is correct
3 Correct 89 ms 9456 KB Output is correct
4 Correct 97 ms 9908 KB Output is correct
5 Correct 97 ms 9808 KB Output is correct
6 Correct 98 ms 10456 KB Output is correct
7 Correct 115 ms 10356 KB Output is correct
8 Correct 81 ms 9256 KB Output is correct
9 Correct 101 ms 9464 KB Output is correct
10 Correct 95 ms 9696 KB Output is correct
11 Correct 65 ms 8572 KB Output is correct
12 Correct 65 ms 8932 KB Output is correct
13 Correct 64 ms 8884 KB Output is correct
14 Correct 95 ms 9808 KB Output is correct
15 Correct 96 ms 9660 KB Output is correct
16 Correct 82 ms 9224 KB Output is correct
17 Correct 95 ms 9764 KB Output is correct
18 Correct 97 ms 9916 KB Output is correct
19 Correct 94 ms 9836 KB Output is correct
20 Correct 92 ms 9804 KB Output is correct
21 Correct 100 ms 10208 KB Output is correct
22 Correct 96 ms 10092 KB Output is correct
23 Correct 90 ms 9924 KB Output is correct
24 Correct 98 ms 9868 KB Output is correct
25 Correct 110 ms 10092 KB Output is correct
26 Correct 103 ms 9740 KB Output is correct
27 Correct 99 ms 9508 KB Output is correct
28 Correct 64 ms 8940 KB Output is correct
29 Correct 63 ms 8764 KB Output is correct
30 Correct 67 ms 8908 KB Output is correct
31 Correct 66 ms 9028 KB Output is correct
32 Correct 69 ms 8624 KB Output is correct
33 Correct 69 ms 8960 KB Output is correct
34 Correct 63 ms 8920 KB Output is correct
35 Correct 73 ms 8836 KB Output is correct
36 Correct 67 ms 8848 KB Output is correct
37 Correct 74 ms 8992 KB Output is correct
38 Correct 65 ms 8764 KB Output is correct
39 Correct 66 ms 8864 KB Output is correct
40 Correct 63 ms 8860 KB Output is correct
41 Correct 67 ms 8692 KB Output is correct
42 Correct 64 ms 8948 KB Output is correct
43 Correct 64 ms 9020 KB Output is correct
44 Correct 167 ms 18660 KB Output is correct
45 Correct 123 ms 12936 KB Output is correct
46 Correct 148 ms 15380 KB Output is correct
47 Correct 149 ms 15284 KB Output is correct
48 Correct 154 ms 17800 KB Output is correct
49 Correct 174 ms 19532 KB Output is correct
50 Correct 171 ms 16624 KB Output is correct
51 Correct 200 ms 18192 KB Output is correct
52 Correct 204 ms 16804 KB Output is correct
53 Correct 120 ms 12212 KB Output is correct
54 Correct 157 ms 17588 KB Output is correct
55 Correct 160 ms 17868 KB Output is correct