結果

問題 No.1619 Coccinellidae
ユーザー tentententen
提出日時 2021-07-26 17:12:36
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,039 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 75,000 KB
実行使用メモリ 57,376 KB
最終ジャッジ日時 2023-09-29 13:55:34
合計ジャッジ時間 7,087 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,540 KB
testcase_01 AC 156 ms
55,548 KB
testcase_02 WA -
testcase_03 AC 43 ms
49,636 KB
testcase_04 AC 159 ms
54,832 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 141 ms
54,332 KB
testcase_08 WA -
testcase_09 AC 43 ms
49,404 KB
testcase_10 AC 111 ms
52,836 KB
testcase_11 WA -
testcase_12 AC 44 ms
47,720 KB
testcase_13 AC 167 ms
55,008 KB
testcase_14 WA -
testcase_15 AC 43 ms
49,448 KB
testcase_16 AC 43 ms
47,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long m = sc.nextLong();
        long last = m - (long)(n - 1) * (n - 2) / 2;
        long k = sc.nextLong();
        long[] ans = new long[n];
        Arrays.fill(ans, -1L);
        int min = 0;
        int max = n - 1;
        BinaryIndexedTree bit = new BinaryIndexedTree(n + 1);
        for (int i = 0; i < n - 1; i++) {
            if (k == 0) {
                ans[min] = i;
                while (ans[min] >= 0) {
                    min++;
                }
            } else if (max - bit.getSum(max + 1) <= k) {
                k -= max - bit.getSum(max + 1);
                ans[max] = i;
                bit.add(max + 1, 1);
                while (ans[max] >= 0) {
                    max--;
                }
            } else {
                int left = min;
                int right = max;
                while (right - left > 1) {
                    int mm = (left + right) / 2;
                    if (mm - bit.getSum(mm + 1) <= k) {
                        left = mm;
                    } else {
                        right = mm;
                    }
                }
                ans[left] = i;
                bit.add(left, 1);
                while (ans[min] >= 0) {
                    min++;
                }
            }
        }
        ans[min] = last;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(ans[i]).append("\n");
        }
        System.out.print(sb);
    }
}
class BinaryIndexedTree {
    int size;
    int[] tree;
    
    public BinaryIndexedTree(int size) {
        this.size = size;
        tree = new int[size];
    }
    
    public void add(int idx, int value) {
        int mask = 1;
        while (idx < size) {
            if ((idx & mask) != 0) {
                tree[idx] += value;
                idx += mask;
            }
            mask <<= 1;
        }
    }
    
    public int getSum(int from, int to) {
        return getSum(to) - getSum(from - 1);
    }
    
    public int getSum(int x) {
        int mask = 1;
        int ans = 0;
        while (x > 0) {
            if ((x & mask) != 0) {
                ans += tree[x];
                x -= mask;
            }
            mask <<= 1;
        }
        return ans;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0