@@ -0,0 +1,2526 @@
+//https://www.hackerrank.com/challenges/library-query%0Aimport java.io.*;%0Aimport java.util.*;%0A%0Apublic class Solution %7B%0A    %0A    final private static short MAX_N = 10000;%0A    final private static short MAX_BOOKS = 1000;%0A    %0A    public static void main(String%5B%5D args) throws IOException %7B%0A        StringBuffer sb = new StringBuffer();%0A        %0A        //INITIALIZE ORDER%0A        short%5B%5D sizes = new short%5BMAX_BOOKS%5D;%0A        short%5B%5D%5B%5D order = new short%5BMAX_BOOKS%5D%5BMAX_N%5D;%0A        short%5B%5D shelves = new short%5BMAX_N%5D;%0A        %0A        //FOR EACH TEST%0A        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A        for(byte T = Byte.parseByte(br.readLine()); T %3E 0; --T)%7B%0A            %0A            //INPUT%0A            final short N = Short.parseShort(br.readLine());%0A            String%5B%5D input = br.readLine().split(%22 %22);%0A            for(short i = 0; i %3C N; ++i)%7B%0A                shelves%5Bi%5D = (short)(Short.parseShort(input%5Bi%5D) - 1);%0A            %7D%0A            %0A            //FOR EACH QUERY%0A            for(short Q = Short.parseShort(br.readLine()); Q %3E 0; --Q)%7B%0A                input = br.readLine().split(%22 %22);%0A                final short X = (short)(Short.parseShort(input%5B1%5D) - 1);%0A                %0A                //READ%0A                if (%220%22.equals(input%5B0%5D))%7B%0A                    final short Y = (short)(Short.parseShort(input%5B2%5D) - 1);%0A                    final short K = (short)(Short.parseShort(input%5B3%5D) - 1);%0A                    %0A                    //SORT%0A                    for(short i = 0; i %3C MAX_BOOKS; sizes%5Bi++%5D = 0)%7B%7D%0A                    for(short i = X; i %3C= Y; ++i)%7B%0A                        final short numBooks = shelves%5Bi%5D;%0A                        order%5BnumBooks%5D%5Bsizes%5BnumBooks%5D++%5D = i;%0A                    %7D%0A                    %0A                    //GET KTH%0A                    short x = 0;%0A                    for(short i = 0; i %3C MAX_BOOKS; ++i)%7B%0A                        short s = sizes%5Bi%5D;%0A                        if ((x += s) %3E K)%7B%0A                            x = order%5Bi%5D%5BK - (x - s)%5D;%0A                            break;%0A                        %7D%0A                    %7D%0A                    %0A                    //OUTPUT%0A                    sb.append((shelves%5Bx%5D + 1) + %22%5Cn%22);%0A                %0A                //UPDATE%0A                %7D else /*if(%221%22.equals(input%5B0%5D))*/%7B%0A                    final short K = (short)(Short.parseShort(input%5B2%5D) - 1);%0A                    shelves%5BX%5D = K;%0A                %7D%0A            %7D%0A        %7D%0A        %0A        System.out.print(sb);%0A    %7D%0A%7D%0A

Create library-query.java