結果

問題 No.2961 Shiny Monster Master
ユーザー ks2m
提出日時 2024-11-16 15:38:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 645 ms / 1,777 ms
コード長 872 bytes
コンパイル時間 3,382 ms
コンパイル使用メモリ 76,988 KB
実行使用メモリ 52,512 KB
最終ジャッジ日時 2024-11-16 15:38:51
合計ジャッジ時間 38,142 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 77
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static int t, n;
	static int[] c;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		t = sc.nextInt();
		n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = sc.nextInt() - 1;
			r[i] = sc.nextInt();
		}
		sc.close();

		c = new int[t];
		for (int i = 0; i < n; i++) {
			c[a[i]]++;
		}
		for (int i = 1; i < t; i++) {
			c[i] += c[i - 1];
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			int ans = f(r[i]) - f(l[i]);
			pw.println(ans);
		}
		pw.flush();
	}

	static int f(int x) {
		int ret = x / t * n;
		ret += c[x % t];
		return ret;
	}
}
0