import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Queue; import java.util.Random; import java.util.function.IntBinaryOperator; import java.util.function.IntFunction; import java.util.function.IntToDoubleFunction; import java.util.function.IntToLongFunction; import java.util.function.IntUnaryOperator; import java.util.function.LongBinaryOperator; import java.util.function.Predicate; import java.util.function.ToIntFunction; import java.util.random.RandomGenerator; import java.util.stream.IntStream; import java.util.stream.Stream; public class Main { static MyPrintWriter pw = MyPrintWriter.getInstance(); static FastScanner sc = FastScanner.getInstance(); public static void main(String[] args) throws IOException { Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1)); new Main().run(); pw.flush(); } void run() { int N = sc.nextInt(); int Q = sc.nextInt(); int[] S = sc.nextInts(N); var ds = new StaticPointAddRangeSum1D(S); for (int QUERY = 0; QUERY < Q; QUERY++) { int L = sc.nextInt() - 1; int R = sc.nextInt(); int K = sc.nextInt(); long ans = ds.getRangeSum(L, R); pw.println(ans); } } } class ArrayUtils { /** * b[i] = a[1] + a[2] + .. + a[i] * * @param a * @return */ public static long[] prefixSum(long[] a) { long[] b = new long[a.length]; for (int i = 0; i < b.length; ++i) { b[i] = (i == 0 ? 0 : b[i - 1]) + a[i]; } return b; } } class FastScanner { private static FastScanner instance = null; private final InputStream in = System.in; private final byte[] buffer = new byte[1 << 16]; private int ptr = 0; private int buflen = 0; private FastScanner() { } public static FastScanner getInstance() { if (instance == null) { instance = new FastScanner(); } return instance; } private boolean hasNextByte() { if (ptr < buflen) { return true; } ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } return buflen > 0; } private int readByte() { if (hasNextByte()) { return buffer[ptr++]; } else { return -1; } } private boolean isPrintableChar(int c) { return (33 <= c) && (c <= 126); } public boolean hasNext() { while (hasNextByte() && (!isPrintableChar(buffer[ptr]))) { ptr++; } return hasNextByte(); } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } while ((b >= '0') && (b <= '9')) { // n = n * 10 + (b - '0'); n = ((n << 1) + (n << 3)) + (b - '0'); b = readByte(); } return minus ? -n : n; } public int nextInt() { return ((int) (nextLong())); } public int[] nextInts(int n) { int[] a = new int[n]; for (int i = 0; i < n; ++i) { a[i] = nextInt(); } return a; } } class MyPrintWriter extends PrintWriter { private static MyPrintWriter instance = null; private MyPrintWriter() { super(System.out); } public static MyPrintWriter getInstance() { if (instance == null) { instance = new MyPrintWriter(); } return instance; } } class StaticPointAddRangeSum1D { int N; long[] A; boolean isBuilt = false; /** * 座標iにa[i]を足して初期化する * * @param N */ public StaticPointAddRangeSum1D(int[] a) { this.N = a.length; A = new long[N]; for (int i = 0; i < A.length; i++) { add(i, a[i]); } } public void add(int i, long val) { A[i] += val; } void build() { if (isBuilt) { throw new AssertionError(); } A = ArrayUtils.prefixSum(A); isBuilt = true; } /** * verified:https://atcoder.jp/contests/abc347/submissions/71277574 */ public long getRangeSum(int leftInclusive, int rightExclusive) { if (!isBuilt) { build(); } leftInclusive = Math.max(leftInclusive, 0); rightExclusive = Math.min(rightExclusive, A.length); if (rightExclusive <= leftInclusive) { return 0; } return A[rightExclusive - 1] - (leftInclusive == 0 ? 0 : A[leftInclusive - 1]); } } // --- Original Code --- // // // import java.io.IOException; // import java.util.ArrayList; // import java.util.Arrays; // // import library.tools.FastScanner; // import library.tools.MergeFiles; // import library.tools.MyPrintWriter; // import library.util.ArrayUtils; // import library.util.Fp; // import library.util.collections.LongArrayList; // import library.util.fold.StaticPointAddRangeSum1D; // import library.util.graph.ImplicitDigraph; // // public class Main { // static MyPrintWriter pw = MyPrintWriter.getInstance(); // static FastScanner sc = FastScanner.getInstance(); // // public static void main(String[] args) throws IOException { // new Main().run(); // pw.flush(); // MergeFiles.export(); // } // // // void run() { // int N=sc.nextInt(); // int Q=sc.nextInt(); // int[]S=sc.nextInts(N); // var ds=new StaticPointAddRangeSum1D(S); // for (int QUERY = 0; QUERY < Q; QUERY++) { // int L=sc.nextInt()-1; // int R=sc.nextInt(); // int K=sc.nextInt(); // long ans=ds.getRangeSum(L, R); // pw.println(ans); // } // } // // void tr(Object... objects) { // System.out.println(Arrays.deepToString(objects)); // } // } //