提出 #76079528


ソースコード 拡げる

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        
        int n = Integer.parseInt(st.nextToken());
        int q = Integer.parseInt(st.nextToken());
        
        int[] totalAdded = new int[n + 1];
        
        int[] freqOfTotal = new int[n + q + 2];
        freqOfTotal[0] = n; 
        
        int[] suffixCount = new int[n + q + 2];
        suffixCount[0] = n; 
        
        int removedBlocks = 0; 
        int zeroCount = n;   
        
        StringBuilder output = new StringBuilder();
        
        for (int i = 0; i < q; i++) {
            st = new StringTokenizer(br.readLine());
            int type = Integer.parseInt(st.nextToken());
            int val = Integer.parseInt(st.nextToken());
            
            if (type == 1) {
                int x = val;
                int currentBlocks = totalAdded[x] - removedBlocks;
                
                if (currentBlocks == 0) {
                    zeroCount--;
                }
                
                int oldTotal = totalAdded[x];
                totalAdded[x]++;
                int newTotal = totalAdded[x];
                
                freqOfTotal[oldTotal]--;
                freqOfTotal[newTotal]++;
    
                suffixCount[newTotal]++;
   
                if (zeroCount == 0) {
                    removedBlocks++;
                    zeroCount = freqOfTotal[removedBlocks];
                }
                
            } else {
                int y = val;
            
                int targetTotal = y + removedBlocks;
                
                if (targetTotal >= suffixCount.length) {
                    output.append(0).append("\n");
                } else {
                    output.append(suffixCount[targetTotal]).append("\n");
                }
            }
        }
        
        System.out.print(output);
    }
}

提出情報

提出日時
問題 C - Drop Blocks
ユーザ renu_
言語 Java24 (OpenJDK 24.0.2)
得点 300
コード長 2248 Byte
結果 AC
実行時間 254 ms
メモリ 68736 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 1
AC × 50
セット名 テストケース
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, hand_24.txt, hand_25.txt, hand_26.txt, hand_27.txt, hand_28.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 46 ms 37692 KiB
hand_00.txt AC 225 ms 66000 KiB
hand_01.txt AC 222 ms 65928 KiB
hand_02.txt AC 254 ms 64560 KiB
hand_03.txt AC 215 ms 64832 KiB
hand_04.txt AC 240 ms 66084 KiB
hand_05.txt AC 210 ms 62560 KiB
hand_06.txt AC 212 ms 64748 KiB
hand_07.txt AC 182 ms 60996 KiB
hand_08.txt AC 208 ms 61936 KiB
hand_09.txt AC 203 ms 61760 KiB
hand_10.txt AC 204 ms 61876 KiB
hand_11.txt AC 203 ms 62224 KiB
hand_12.txt AC 191 ms 61836 KiB
hand_13.txt AC 223 ms 64468 KiB
hand_14.txt AC 232 ms 65932 KiB
hand_15.txt AC 220 ms 62640 KiB
hand_16.txt AC 41 ms 37636 KiB
hand_17.txt AC 229 ms 67020 KiB
hand_18.txt AC 181 ms 62120 KiB
hand_19.txt AC 186 ms 61172 KiB
hand_20.txt AC 187 ms 61124 KiB
hand_21.txt AC 243 ms 68360 KiB
hand_22.txt AC 226 ms 66764 KiB
hand_23.txt AC 217 ms 67304 KiB
hand_24.txt AC 219 ms 68736 KiB
hand_25.txt AC 43 ms 40988 KiB
hand_26.txt AC 43 ms 41364 KiB
hand_27.txt AC 115 ms 50076 KiB
hand_28.txt AC 203 ms 62952 KiB
random_00.txt AC 215 ms 64120 KiB
random_01.txt AC 211 ms 63752 KiB
random_02.txt AC 221 ms 62836 KiB
random_03.txt AC 220 ms 64776 KiB
random_04.txt AC 224 ms 64328 KiB
random_05.txt AC 209 ms 61616 KiB
random_06.txt AC 204 ms 61248 KiB
random_07.txt AC 251 ms 66196 KiB
random_08.txt AC 223 ms 63492 KiB
random_09.txt AC 224 ms 63268 KiB
random_10.txt AC 212 ms 61888 KiB
random_11.txt AC 208 ms 61540 KiB
random_12.txt AC 249 ms 65184 KiB
random_13.txt AC 221 ms 62960 KiB
random_14.txt AC 220 ms 65024 KiB
random_15.txt AC 192 ms 62620 KiB
random_16.txt AC 222 ms 62812 KiB
random_17.txt AC 204 ms 64156 KiB
random_18.txt AC 238 ms 63148 KiB
random_19.txt AC 227 ms 63464 KiB