結果

問題 No.618 labo-index
ユーザー htensaihtensai
提出日時 2020-02-13 11:47:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,401 ms / 6,000 ms
コード長 1,601 bytes
コンパイル時間 2,753 ms
コンパイル使用メモリ 80,316 KB
実行使用メモリ 65,584 KB
最終ジャッジ日時 2024-04-15 14:11:46
合計ジャッジ時間 30,650 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
41,336 KB
testcase_01 AC 138 ms
41,216 KB
testcase_02 AC 137 ms
41,196 KB
testcase_03 AC 140 ms
41,424 KB
testcase_04 AC 217 ms
43,600 KB
testcase_05 AC 224 ms
43,972 KB
testcase_06 AC 154 ms
41,508 KB
testcase_07 AC 197 ms
42,340 KB
testcase_08 AC 200 ms
42,084 KB
testcase_09 AC 210 ms
43,048 KB
testcase_10 AC 221 ms
43,536 KB
testcase_11 AC 197 ms
42,624 KB
testcase_12 AC 208 ms
42,892 KB
testcase_13 AC 217 ms
43,056 KB
testcase_14 AC 207 ms
43,008 KB
testcase_15 AC 219 ms
43,980 KB
testcase_16 AC 224 ms
44,044 KB
testcase_17 AC 207 ms
42,808 KB
testcase_18 AC 237 ms
45,504 KB
testcase_19 AC 959 ms
56,808 KB
testcase_20 AC 950 ms
58,728 KB
testcase_21 AC 918 ms
57,068 KB
testcase_22 AC 929 ms
59,156 KB
testcase_23 AC 1,001 ms
58,696 KB
testcase_24 AC 896 ms
58,268 KB
testcase_25 AC 940 ms
58,992 KB
testcase_26 AC 943 ms
58,456 KB
testcase_27 AC 942 ms
58,192 KB
testcase_28 AC 891 ms
57,468 KB
testcase_29 AC 929 ms
58,060 KB
testcase_30 AC 921 ms
56,880 KB
testcase_31 AC 929 ms
57,204 KB
testcase_32 AC 942 ms
58,964 KB
testcase_33 AC 957 ms
58,952 KB
testcase_34 AC 1,707 ms
64,936 KB
testcase_35 AC 1,659 ms
65,584 KB
testcase_36 AC 1,100 ms
62,440 KB
testcase_37 AC 2,401 ms
62,492 KB
testcase_38 AC 138 ms
41,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        ArrayList<Long> order = new ArrayList<>();
        ArrayList<Long> current = new ArrayList<>();
        current.add(Long.MIN_VALUE);
        current.add(Long.MAX_VALUE);
        long added = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int t = sc.nextInt();
            int x = sc.nextInt();
            if (t == 1) {
                int left = 0;
                int right = current.size() - 1;
                long y = x - added;
                while (right - left > 1) {
                    int m = (left + right) / 2;
                    if (current.get(m) <= y) {
                        left = m;
                    } else {
                        right = m;
                    }
                }
                current.add(right, y);
                order.add(y);
            } else if (t == 2) {
                current.remove(order.get(x - 1));
            } else {
                added += x;
            }
            int left = 0;
            int right = current.size() - 1;
            while(right - left > 1) {
                int m = (left + right) / 2;
                if (current.get(m) + added >= current.size() - m - 1) {
                    right = m;
                } else {
                    left = m;
                }
            }
            sb.append(current.size() - right - 1).append("\n");
        }
        System.out.print(sb);
    }
}
0