結果

問題 No.1742 Binary Indexed Train
ユーザー tentententen
提出日時 2023-04-13 11:12:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 524 ms / 3,000 ms
コード長 2,132 bytes
コンパイル時間 4,556 ms
コンパイル使用メモリ 90,440 KB
実行使用メモリ 57,884 KB
最終ジャッジ日時 2024-04-17 15:59:27
合計ジャッジ時間 14,534 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
36,952 KB
testcase_01 AC 47 ms
37,168 KB
testcase_02 AC 45 ms
37,096 KB
testcase_03 AC 415 ms
56,648 KB
testcase_04 AC 433 ms
56,828 KB
testcase_05 AC 427 ms
56,260 KB
testcase_06 AC 239 ms
47,256 KB
testcase_07 AC 231 ms
47,424 KB
testcase_08 AC 478 ms
57,296 KB
testcase_09 AC 442 ms
48,236 KB
testcase_10 AC 524 ms
57,020 KB
testcase_11 AC 484 ms
57,884 KB
testcase_12 AC 366 ms
48,356 KB
testcase_13 AC 413 ms
56,316 KB
testcase_14 AC 399 ms
57,000 KB
testcase_15 AC 191 ms
48,708 KB
testcase_16 AC 172 ms
47,812 KB
testcase_17 AC 309 ms
51,660 KB
testcase_18 AC 283 ms
52,360 KB
testcase_19 AC 216 ms
46,932 KB
testcase_20 AC 116 ms
40,180 KB
testcase_21 AC 209 ms
49,344 KB
testcase_22 AC 364 ms
54,972 KB
testcase_23 AC 136 ms
40,708 KB
testcase_24 AC 118 ms
39,716 KB
testcase_25 AC 338 ms
54,848 KB
testcase_26 AC 223 ms
49,156 KB
testcase_27 AC 273 ms
52,756 KB
testcase_28 AC 137 ms
41,528 KB
testcase_29 AC 361 ms
55,268 KB
testcase_30 AC 233 ms
51,396 KB
testcase_31 AC 439 ms
56,072 KB
testcase_32 AC 221 ms
50,792 KB
testcase_33 AC 159 ms
44,556 KB
testcase_34 AC 308 ms
52,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            long s = sc.nextLong();
            long t = sc.nextLong();
            int count = 0;
            for (int i = 0; s + (1L << i) <= t; i++) {
                if ((s & (1L << i)) > 0) {
                    count++;
                    s += (1L << i);
                }
            }
            count += getPop(s ^ t);
            sb.append(count).append("\n");
        }
        System.out.print(sb);
    }
    
    static int getPop(long x) {
        long pop = 0;
        while (x > 0) {
            pop += x % 2;
            x >>= 1;
        }
        return (int)pop;
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0