/* * Solution Template for Conformity * * Australian Informatics Olympiad 2026 Invitationals * * This file is provided to assist with reading of input and writing of output * for the problem. You may modify this file however you wish, or * you may choose not to use this file at all. */ import java.io.*; class Solution { /* N is the number of pillars and Q is the number of questions. */ private static int N; private static int Q; /* H contains the pillar heights. The array starts from 0. */ private static int H[] = new int[200005]; /* L and R contain the inclusive, 1-based question endpoints. */ private static int L[] = new int[200005]; private static int R[] = new int[200005]; private static long answer; /* * Read the next token from the input file. * Tokens are separated by whitespace, i.e., spaces, tabs and newlines. * If end-of-file is reached then an empty string is returned. */ private static String readToken(BufferedReader in) throws IOException { StringBuffer ans = new StringBuffer(); int next; /* Skip any initial whitespace. */ next = in.read(); while (next >= 0 && Character.isWhitespace((char)next)) next = in.read(); /* Read the following token. */ while (next >= 0 && ! Character.isWhitespace((char)next)) { ans.append((char)next); next = in.read(); } return ans.toString(); } public static void main(String[] args) throws IOException { /* Open the input and output streams for stdin and stdout. */ BufferedReader input_reader = new BufferedReader(new InputStreamReader( System.in)); BufferedWriter output_writer = new BufferedWriter(new OutputStreamWriter( System.out)); /* Read the pillars and questions. */ N = Integer.parseInt(readToken(input_reader)); Q = Integer.parseInt(readToken(input_reader)); for (int i = 0; i < N; i++) { H[i] = Integer.parseInt(readToken(input_reader)); } for (int i = 0; i < Q; i++) { L[i] = Integer.parseInt(readToken(input_reader)); R[i] = Integer.parseInt(readToken(input_reader)); } /* * TODO: Answer every question independently. An answer may exceed 32-bit * integer range. */ for (int i = 0; i < Q; i++) { output_writer.write(answer + "\n"); } /* Close the input_reader and output_writer. */ input_reader.close(); output_writer.close(); } }