ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1028. Stars

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 ?
Posted by gautamvs 3 Nov 2013 18:12
In Java, Scanner for input consumes extra time, so TLE.
Using BufferedReader for input may help.
Re: Java BIT gets TLE, C++ AC ?
Posted by Emin Hesenov 29 Mar 2016 22:28
salam