Submission #553181

# Submission time Handle Problem Language Result Execution time Memory
553181 2022-04-25T02:56:51 Z tutest Monkey and Apple-trees (IZhO12_apple) Java 11
Compilation error
0 ms 0 KB
import java.io.*;
import java.util.StringTokenizer;

import java.util.*;

class FastIO {
    public static class InputClass {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputClass(InputStream inputSteam) {
            reader = new BufferedReader(new InputStreamReader(inputSteam));
            tokenizer = new StringTokenizer("");
        }

        public boolean hasNext() {
            try {
                while (!tokenizer.hasMoreTokens()) {
                    String line = reader.readLine();
                    if (line == null)
                        return false; // EOF
                    tokenizer = new StringTokenizer(line);
                }
            } catch (Exception e) {
            }
            return true;
        }

        public String next() {
            try {
                return hasNext() ? tokenizer.nextToken() : null;
            } catch (Exception e) {
            }
            return null;
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
            }
            return null;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    public algorithm.FastIO.InputClass in;
    public PrintWriter out;

    public FastIO() {
        in = new algorithm.FastIO.InputClass(System.in);
        out = new PrintWriter(new OutputStreamWriter(System.out));
    }

    public FastIO(String inputFile, String outputFile) {
        try {
            in = inputFile == null ? new algorithm.FastIO.InputClass(System.in) : new algorithm.FastIO.InputClass(new FileInputStream(inputFile));
            out = outputFile == null ? new PrintWriter(new OutputStreamWriter(System.out)) :
                    new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile)));
        } catch (Exception e) {
        }
    }
}


public class apple {

    // Tested by Leetcode 307
    static class SparseSegmentTreeRangeSum {
        private static class TreeNode {
            TreeNode left, right;
            long sum;
            long lazyValue;
        }

        private TreeNode root;
        private final long L, R;

        public SparseSegmentTreeRangeSum(long low, long high) {
            L = low;
            R = high;
            root = new TreeNode();
        }

        private void pushdown(TreeNode root, long L, long R, long value) {
            if (root != null && L != R) {
                if (root.left == null) root.left = new TreeNode();
                if (root.right == null) root.right = new TreeNode();
            }
            if (root != null && root.lazyValue > 0 && L != R) {
                long M = L + ((R - L) >>> 1);
                root.left.sum = (M - L + 1);
                root.left.lazyValue = value;

                root.right.sum = (R - (M + 1) + 1);
                root.right.lazyValue = value;

                root.lazyValue = 0;
            }
        }

        public void update(long low, long high, long value) {
            update(low, high, value, L, R, root);
        }

        private void update(long low, long high, long value, long L, long R, TreeNode root) {
            if (high < L || R < low) return;
            if (low <= L && R <= high) {
                root.sum = (R - L + 1) * value;
                root.lazyValue = value;
                return;
            }
            pushdown(root, L, R, 1);
            long M = L + ((R - L) >>> 1);
            update(low, high, value, L, M, root.left);
            update(low, high, value, M + 1, R, root.right);
            root.sum = root.left.sum + root.right.sum;
        }

        // Sum[low...high] inclusive
        public long getSum(long low, long high) {
            return getSum(low, high, L, R, root);
        }

        // low, high is range of query
        // L, R are range of TreeNode.
        private long getSum(long low, long high, long L, long R, TreeNode root) {
            if (low > high || root == null) return 0L;
            if (low <= L && R <= high) {
                return root.sum;
            }
            pushdown(root, L, R, 1);
            long M = L + ((R - L) >>> 1);
            if (high <= M) {
                return getSum(low, high, L, M, root.left);
            } else if (M + 1 <= low) {
                return getSum(low, high, M + 1, R, root.right);
            } else {
                return getSum(low, high, L, M, root.left) + getSum(low, high, M + 1, R, root.right);
            }
        }
    }

    public static void main(String[] args) throws Exception {
        FastIO io = new FastIO();

        SparseSegmentTreeRangeSum tree = new  SparseSegmentTreeRangeSum(1, 1_000_000_000 + 10);
        int M = io.in.nextInt();
        int D, X, Y, C;
        C = 0;
        while (M-- > 0) {
            D = io.in.nextInt();
            X = io.in.nextInt();
            Y = io.in.nextInt();

            if (D == 1) {
                C = (int) tree.getSum(X + C, Y + C);
                io.out.println(C);
            } else {
                tree.update(X + C, Y + C, 1);
            }
        }

        io.out.flush();
    }
}

Compilation message

apple.java:58: error: package algorithm.FastIO does not exist
    public algorithm.FastIO.InputClass in;
                           ^
apple.java:62: error: package algorithm.FastIO does not exist
        in = new algorithm.FastIO.InputClass(System.in);
                                 ^
apple.java:68: error: package algorithm.FastIO does not exist
            in = inputFile == null ? new algorithm.FastIO.InputClass(System.in) : new algorithm.FastIO.InputClass(new FileInputStream(inputFile));
                                                         ^
apple.java:68: error: package algorithm.FastIO does not exist
            in = inputFile == null ? new algorithm.FastIO.InputClass(System.in) : new algorithm.FastIO.InputClass(new FileInputStream(inputFile));
                                                                                                      ^
4 errors