General

# Author Problem Lang Verdict Time Memory Sent Judged
12877177 Practice:
m.khooryani
433B - 23 Java 7 Time limit exceeded on test 46 2000 ms 2716 KB 2015-09-06 23:26:57 2015-09-06 23:26:57

→ Source
import java.awt.Point;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
*
* @author Mojtaba
*/
public class Main {

public static void main(String[] args) throws IOException {
MyScanner in = new MyScanner(System.in);
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
StringBuilder sb = new StringBuilder("");

int n = in.nextInt();
int[] a = in.nextIntegerArray(n);
long[] v = new long[n + 1];
for (int i = 1; i <= a.length; i++) {
v[i] = v[i - 1] + a[i - 1];
}
long[] u = new long[n + 1];
Arrays.sort(a);
for (int i = 1; i <= a.length; i++) {
u[i] = u[i - 1] + a[i - 1];
}
int m = in.nextInt();
for (int i = 0; i < m; i++) {
int type = in.nextInt();
int l = in.nextInt();
int r = in.nextInt();
sb.append(type == 1 ? v[r] - v[l - 1] : u[r] - u[l - 1]).append("\n");
}

//System.out.println(sb.toString().trim());
writer.println(sb.toString().trim());
writer.flush();
in.close();
}
}

class MyScanner {

StringTokenizer tokenizer;

public MyScanner(InputStream stream) {
}

public int nextInt() throws IOException {
return Integer.parseInt(next());
}

public int[] nextIntegerArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}

public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextLong();
}
return a;
}

public int nextInt(int radix) throws IOException {
}

public long nextLong() throws IOException {
return Long.parseLong(next());
}

public long nextLong(int radix) throws IOException {
}

public double nextDouble() throws IOException {
return Double.parseDouble(next());
}

public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}

public BigInteger nextBigInteger(int radix) throws IOException {
}

public String next() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
return this.next();
}
}

public void close() throws IOException {
}
}

?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?