제출 #1207355

#제출 시각아이디문제언어결과실행 시간메모리
1207355maryam원숭이와 사과 나무 (IZhO12_apple)Java
컴파일 에러
0 ms0 KiB
import java.io.*;
 
public class Main {
    static final long SZ = (long) 2e18;
 
    static class Node {
        long sum = 0;
        boolean lazy = false;
        Node left, right;
 
        void push(long nl, long nr) {
            if (!lazy) return;
            sum = nr - nl + 1;
            if (nl != nr) {
                if (left == null) left = new Node();
                if (right == null) right = new Node();
                left.lazy = right.lazy = true;
            }
            lazy = false;
        }
 
        void add(long nl, long nr, long l, long r) {
            push(nl, nr);
            if (nr < l || nl > r) return;
            if (nl >= l && nr <= r) {
                lazy = true;
                push(nl, nr);
                return;
            }
            long mid = nl + (nr - nl) / 2;
            if (left == null) left = new Node();
            if (right == null) right = new Node();
            left.add(nl, mid, l, r);
            right.add(mid + 1, nr, l, r);
            sum = (left != null ? left.sum : 0) + (right != null ? right.sum : 0);
        }
 
        long query(long nl, long nr, long l, long r) {
            push(nl, nr);
            if (nr < l || nl > r) return 0;
            if (nl >= l && nr <= r) return sum;
            long mid = nl + (nr - nl) / 2;
            long res = 0;
            if (left != null) res += left.query(nl, mid, l, r);
            if (right != null) res += right.query(mid + 1, nr, l, r);
            return res;
        }
    }
 
    static class FastReader {
        final private int BUFFER_SIZE = 1 << 16;
        private final DataInputStream din;
        private final byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public FastReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            return neg ? -ret : ret;
        }
 
        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            return neg ? -ret : ret;
        }
 
        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
 
        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
            bufferPointer = 0;
        }
    }
 
    public static void main(String[] args) throws IOException {
        FastReader fr = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
 
        int n = fr.nextInt();
        Node root = new Node();
        long c = 0;
 
        for (int i = 0; i < n; i++) {
            int d = fr.nextInt();
            long l = fr.nextLong() + c;
            long r = fr.nextLong() + c;
            if (d == 1) {
                c = root.query(0, SZ - 1, l, r);
                pw.println(c);
            } else {
                root.add(0, SZ - 1, l, r);
            }
        }
 
        pw.flush();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

apple.java:3: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
1 error

=======