@@ -0,0 +1,2557 @@
+package opencup.xiv.round2;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.io.PrintWriter;%0Aimport java.nio.ByteBuffer;%0Aimport java.nio.channels.FileChannel;%0Aimport java.util.StringTokenizer;%0A%0Apublic class B %7B%0A%0A    private BufferedReader br;%0A    private PrintWriter out;%0A    private StringTokenizer st;%0A%0A    public B() throws IOException %7B%0A        out = new PrintWriter(System.out);%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        new org.mystic.opencup.round2.C().solve();%0A    %7D%0A%0A    public String next() throws IOException %7B%0A        while (st == null %7C%7C !st.hasMoreTokens()) %7B%0A            st = new StringTokenizer(br.readLine());%0A        %7D%0A        return st.nextToken();%0A    %7D%0A%0A    public int nextInt() throws IOException %7B%0A        return Integer.parseInt(next());%0A    %7D%0A%0A    public long nextLong() throws IOException %7B%0A        return Long.parseLong(next());%0A    %7D%0A%0A    private void solve() throws IOException %7B%0A        final FileInputStream reader = new FileInputStream(%22c.in%22);%0A        FileChannel in = reader.getChannel();%0A        final int all = (int) in.size() / 4;%0A        final ByteBuffer buffer = in.map(FileChannel.MapMode.READ_ONLY, 0, in.size());%0A%0A        class Utils %7B%0A            final int getInt(int k) %7B%0A                int ret = 0;%0A                for (int i = 3; i %3E= 0; i--) %7B%0A                    ret %3C%3C= 8;%0A                    ret += (int) (buffer.get(k * 4 + i)) & (1 %3C%3C 8) - 1;%0A                %7D%0A                return ret;%0A            %7D%0A%0A            int binarySearch(int x, int i1, int i2) %7B%0A                //how many numbers in g, %3C= x%0A                int lo = i1 - 1, hi = i2;%0A                while (hi - lo %3E 1) %7B%0A                    int med = lo + hi %3E%3E 1;%0A                    if (getInt(med) %3E x) %7B%0A                        hi = med;%0A                    %7D else lo = med;%0A                %7D%0A                return hi - i1;%0A            %7D%0A        %7D%0A        Utils u = new Utils();%0A        int n = u.getInt(0);%0A        int m = u.getInt(1);%0A        int end = n * m + 2;%0A        for (int j = end; j %3C all; j += 2) %7B%0A            int x = u.getInt(j);%0A            int y = u.getInt(j + 1);%0A            x = Math.max(-1, x);%0A            y = Math.max(-1, y);%0A            int sum = 0;%0A            for (int i = 0; i %3C n; i++) %7B%0A                sum += u.binarySearch(y, i * m + 2, (i + 1) * (m) + 2) - u.binarySearch(x - 1, i * m + 2, (i + 1) * (m) + 2);%0A            %7D%0A            out.println(sum);%0A        %7D%0A        out.flush();%0A        out.close();%0A    %7D%0A%7D%0A

Problem B solution