結果

問題 No.1742 Binary Indexed Train
ユーザー ks2mks2m
提出日時 2021-11-12 22:50:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 847 ms / 3,000 ms
コード長 980 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 73,804 KB
実行使用メモリ 60,744 KB
最終ジャッジ日時 2023-08-17 03:12:06
合計ジャッジ時間 21,406 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,364 KB
testcase_01 AC 44 ms
49,336 KB
testcase_02 AC 44 ms
49,320 KB
testcase_03 AC 827 ms
60,024 KB
testcase_04 AC 787 ms
59,288 KB
testcase_05 AC 847 ms
60,168 KB
testcase_06 AC 357 ms
57,108 KB
testcase_07 AC 351 ms
57,204 KB
testcase_08 AC 759 ms
58,596 KB
testcase_09 AC 800 ms
59,580 KB
testcase_10 AC 766 ms
60,744 KB
testcase_11 AC 757 ms
58,824 KB
testcase_12 AC 784 ms
59,000 KB
testcase_13 AC 796 ms
59,128 KB
testcase_14 AC 767 ms
59,308 KB
testcase_15 AC 307 ms
59,492 KB
testcase_16 AC 305 ms
59,004 KB
testcase_17 AC 517 ms
57,676 KB
testcase_18 AC 478 ms
57,580 KB
testcase_19 AC 314 ms
58,536 KB
testcase_20 AC 149 ms
53,832 KB
testcase_21 AC 321 ms
58,600 KB
testcase_22 AC 532 ms
59,056 KB
testcase_23 AC 172 ms
55,872 KB
testcase_24 AC 132 ms
53,828 KB
testcase_25 AC 483 ms
57,564 KB
testcase_26 AC 357 ms
59,196 KB
testcase_27 AC 538 ms
60,156 KB
testcase_28 AC 181 ms
55,552 KB
testcase_29 AC 530 ms
57,716 KB
testcase_30 AC 509 ms
60,308 KB
testcase_31 AC 837 ms
59,800 KB
testcase_32 AC 465 ms
60,164 KB
testcase_33 AC 243 ms
56,348 KB
testcase_34 AC 592 ms
59,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		long[] s = new long[q];
		long[] t = new long[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			s[i] = Long.parseLong(sa[0]);
			t[i] = Long.parseLong(sa[1]);
		}
		br.close();

		long n2 = 1L << n;
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			long ans = 0;
			long now = s[i];
			while (now < t[i]) {
				long v = Long.lowestOneBit(now);
				if (v == 0) {
					v = n2;
				}
				while (v > 0) {
					if (now % v == 0 && now + v <= t[i]) {
						ans++;
						now += v;
						break;
					}
					v /= 2;
				}
			}
			pw.println(ans);
		}
		pw.flush();
	}
}
0