█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6241

Problema 0xca - Contar cuantas veces aparece X en un subarreglo

  • Autor: rpedrazacoello
  • Fecha: 2022-05-27 02:42:45 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.083 s 16 KBi
#2
Correcto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.092 s 16 KBi
#3
Correcto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.436 s 31 KBi
#4
Tiempo límite excedido
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
1.081 s 114 KBi
#5
Tiempo límite excedido
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
1.056 s 87 KBi
#6
Error en tiempo de ejecución (NZEC)
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.788 s 125 KBi
#7
Error en tiempo de ejecución (NZEC)
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.73 s 125 KBi
#8
Error en tiempo de ejecución (NZEC)
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.761 s 125 KBi
Puntos totales: 38 / 100

Código

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        HashMap<Integer, ArrayList<Integer>> memoization = new HashMap<>();

        for(int i=0; i<n; i++){
            int value = scanner.nextInt();
            if(!memoization.containsKey(value)){
                ArrayList<Integer> arrayList = new ArrayList();
                arrayList.add(i);
                memoization.put(value, arrayList);
            } else {
                memoization.get(value).add(i);
            }
        }

        int c = scanner.nextInt();

        for(int i=0; i<c; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            int x = scanner.nextInt();

            int count = 0;
            if(memoization.containsKey(x)) {
                ArrayList<Integer> arrayList = memoization.get(x);
                for (int j = 0; j < arrayList.size(); j++) {
                    int value = arrayList.get(j);
                    if (value >= l && value <= r) {
                        count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}