|
|
вернуться в форумJava BIT gets TLE, C++ AC ? Послано begi 6 авг 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 ? salam |
|
|