|  | 
|  | 
| back to board | Java BIT gets TLE, C++ AC ? Posted by begi  6 Aug 2013 17:08 First I wrote the program in Java, but I got TLE on test #9, below is my program that gets TLE:
 import java.util.Scanner;
 
 public class Main {
 
 public static int read(int idx, int[] tree){
 int sum = 0;
 while(idx > 0){
 sum += tree[idx];
 idx -= idx & (-idx);
 }
 return sum;
 }
 
 public static void update(int idx, int maxIndex, int[] tree){
 while(idx <= maxIndex){
 tree[idx]++;
 idx += idx & (-idx);
 }
 }
 
 public static void main(String[] args) {
 int N;
 int maxIndex = 32005;
 
 int[] level;
 int[] binaryIndexTree;
 
 Scanner sc = new Scanner(System.in);
 N = sc.nextInt();
 level = new int[N+1];
 binaryIndexTree = new int[maxIndex];
 
 for(int i=0; i<N; i++){
 int x = sc.nextInt();
 int y = sc.nextInt();
 x++;
 level[ read(x, binaryIndexTree) ]++;
 update(x, maxIndex, binaryIndexTree);
 }
 for(int i=0; i<N; i++){
 System.out.println(level[i]);
 }
 
 }
 }
 
 Then I write in C++ and get AC?
 @admins: Please extend time limit for Java.
Re: Java BIT gets TLE, C++ AC ? In Java, Scanner for input consumes extra time, so TLE.Using BufferedReader for input may help.
Re: Java BIT gets TLE, C++ AC ? salamRe: Java BIT gets TLE, C++ AC ? Posted by ASL  4 Jun 2025 20:22I had the same issue and managed to bypass it with submitting the same solution 3 times in a row. I got TLE9, TLE11 and finally AC. My guess it is because of JIT compiler optimizations. | 
 | 
|