結果

問題 No.1742 Binary Indexed Train
ユーザー tentententen
提出日時 2023-06-29 09:05:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 635 ms / 3,000 ms
コード長 2,206 bytes
コンパイル時間 4,094 ms
コンパイル使用メモリ 85,480 KB
実行使用メモリ 55,344 KB
最終ジャッジ日時 2023-09-20 04:42:38
合計ジャッジ時間 19,050 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
33,408 KB
testcase_01 AC 39 ms
33,496 KB
testcase_02 AC 41 ms
33,804 KB
testcase_03 AC 509 ms
54,784 KB
testcase_04 AC 501 ms
53,152 KB
testcase_05 AC 508 ms
53,052 KB
testcase_06 AC 260 ms
43,200 KB
testcase_07 AC 263 ms
43,868 KB
testcase_08 AC 435 ms
45,160 KB
testcase_09 AC 447 ms
54,776 KB
testcase_10 AC 451 ms
55,108 KB
testcase_11 AC 632 ms
54,996 KB
testcase_12 AC 635 ms
55,344 KB
testcase_13 AC 488 ms
53,188 KB
testcase_14 AC 495 ms
53,248 KB
testcase_15 AC 207 ms
45,040 KB
testcase_16 AC 194 ms
45,060 KB
testcase_17 AC 316 ms
43,760 KB
testcase_18 AC 342 ms
50,672 KB
testcase_19 AC 222 ms
42,672 KB
testcase_20 AC 122 ms
36,564 KB
testcase_21 AC 219 ms
44,900 KB
testcase_22 AC 367 ms
51,860 KB
testcase_23 AC 126 ms
36,924 KB
testcase_24 AC 118 ms
36,884 KB
testcase_25 AC 344 ms
52,992 KB
testcase_26 AC 233 ms
43,080 KB
testcase_27 AC 328 ms
49,932 KB
testcase_28 AC 138 ms
37,932 KB
testcase_29 AC 393 ms
52,188 KB
testcase_30 AC 247 ms
47,016 KB
testcase_31 AC 477 ms
52,604 KB
testcase_32 AC 244 ms
47,696 KB
testcase_33 AC 162 ms
42,516 KB
testcase_34 AC 347 ms
50,352 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) {
            int count = 0;
            long s = sc.nextLong();
            long t = sc.nextLong();
            for (int i = 0; i < n; i++) {
                if ((s & (1L << i)) == 0) {
                    continue;
                }
                if (s + (1L << i) > t) {
                    break;
                }
                s += (1L << i);
                count++;
            } 
            sb.append(count + getPop(s ^ t)).append("\n");
        }
        System.out.print(sb);
    }
    
    static long getPop(long x) {
        long pop = 0;
        while (x > 0) {
            pop += x % 2;
            x >>= 1;
        }
        return 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