結果
| 問題 | No.2930 Larger Mex | 
| コンテスト | |
| ユーザー |  aketijyuuzou | 
| 提出日時 | 2025-02-08 10:51:18 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,263 ms / 2,000 ms | 
| コード長 | 6,055 bytes | 
| コンパイル時間 | 6,111 ms | 
| コンパイル使用メモリ | 121,464 KB | 
| 実行使用メモリ | 56,024 KB | 
| 最終ジャッジ日時 | 2025-02-08 10:52:12 | 
| 合計ジャッジ時間 | 49,515 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 50 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
// https://yukicoder.me/problems/no/2930
class Program
{
    static string InputPattern = "InputX";
    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();
        if (InputPattern == "Input1") {
            WillReturn.Add("5 1");
            WillReturn.Add("0 3 1 0 2");
            //2
            //3
            //3
            //2
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4 0");
            WillReturn.Add("1 2 3 4");
            //4
            //3
            //2
            //1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("20 3");
            WillReturn.Add("0 2 1 1 1 5 7 0 2 1 4 1 4 8 0 3 0 0 4 2");
            //0
            //0
            //2
            //3
            //5
            //6
            //9
            //9
            //10
            //10
            //10
            //9
            //8
            //7
            //6
            //5
            //4
            //3
            //2
            //1
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }
    static void Main()
    {
        List<string> InputList = GetInputList();
        long[] wkArr = InputList[0].Split(' ').Select(pX => long.Parse(pX)).ToArray();
        long M = wkArr[1];
        long[] AArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();
        long UB = AArr.GetUpperBound(0);
        // Mexが0の場合
        if (M == 0) {
            for (long I = AArr.Length; 1 <= I; I--) {
                Console.WriteLine(I);
            }
            return;
        }
        // 件数[値]なDict
        var CntDict = new Dictionary<long, long>();
        if (AArr[0] <= M) {
            DictIncrement(CntDict, AArr[0]);
        }
        var InsDualSegmentTree = new DualSegmentTree(AArr.Length);
        long R = 0;
        for (long L = 0; L <= UB; L++) {
            while (R + 1 <= UB) {
                if (CntDict.Count == M) {
                    break;
                }
                if (AArr[R + 1] <= M - 1) {
                    long CurrVal = AArr[R + 1];
                    DictIncrement(CntDict, CurrVal);
                    if (CntDict.Count == M) {
                        R++;
                        break;
                    }
                }
                R++;
            }
            if (CntDict.Count == M) {
                //Console.WriteLine("左端{0}だと右端は{1}", L, R);
                long LenMin = R - L + 1;
                long LenMax = UB - L + 1;
                InsDualSegmentTree.RangeAdd(LenMin, LenMax, 1);
            }
            if (AArr[L] <= M - 1) {
                DictDecrement(CntDict, AArr[L]);
            }
        }
        for (long I = 1; I <= AArr.Length; I++) {
            Console.WriteLine(InsDualSegmentTree[I]);
        }
    }
    // Dictの指定したキーの値をインクリメント
    static void DictIncrement(Dictionary<long, long> pDict, long pKey)
    {
        if (pDict.ContainsKey(pKey) == false) {
            pDict[pKey] = 0;
        }
        pDict[pKey]++;
    }
    // Dictの指定したキーの値をデクリメント
    static void DictDecrement(Dictionary<long, long> pDict, long pKey)
    {
        if (--pDict[pKey] == 0) {
            pDict.Remove(pKey);
        }
    }
}
// 区間加算、1点取得な双対セグ木(フェニック木使用)
#region DualSegmentTree
internal class DualSegmentTree
{
    private long[] mBitArr; // 内部配列(1オリジンなため、添字0は未使用)
    private long mExternalArrUB;
    // ノードのIndexの列挙を返す
    internal IEnumerable<long> GetNodeIndEnum()
    {
        for (long I = 0; I <= GetUB(); I++) {
            yield return I;
        }
    }
    // ノードのUBを返す
    internal long GetUB()
    {
        return mExternalArrUB;
    }
    // コンストラクタ
    // フェニック木の外部配列(0オリジン)のUBを指定
    internal DualSegmentTree(long pExternalArrUB)
    {
        mExternalArrUB = pExternalArrUB;
        // フェニック木の外部配列は0オリジンで、
        // フェニック木の内部配列は1オリジンなため、2を足す
        mBitArr = new long[pExternalArrUB + 2];
    }
    // インデクサ
    internal long this[long pInd]
    {
        get { return GetVal(pInd); }
        set { RangeAdd(pInd, pInd, value - GetVal(pInd)); }
    }
    // 双対セグメント木の機能
    // 区間加算
    internal void RangeAdd(long pSta, long pEnd, long AddVal)
    {
        pSta++; // 1オリジンに変更
        pEnd++; // 1オリジンに変更
        long ImosSta = pSta;
        long ImosEnd = pEnd + 1;
        // いもす法
        FenwickTree_Add(ImosSta, AddVal);
        if (ImosEnd <= mBitArr.GetUpperBound(0)) {
            FenwickTree_Add(ImosEnd, -AddVal);
        }
    }
    // 双対セグメント木の機能
    // 1点取得
    internal long GetVal(long pInd)
    {
        pInd++; // 1オリジンに変更
        return FenwickTree_GetSum(1, pInd);
    }
    // フェニック木の機能
    // [pSta,pEnd] のSumを返す
    private long FenwickTree_GetSum(long pSta, long pEnd)
    {
        return FenwickTree_GetSum(pEnd) - FenwickTree_GetSum(pSta - 1);
    }
    // フェニック木の機能
    // [0,pEnd] のSumを返す
    private long FenwickTree_GetSum(long pEnd)
    {
        long Sum = 0;
        while (pEnd >= 1) {
            Sum += mBitArr[pEnd];
            pEnd -= pEnd & -pEnd;
        }
        return Sum;
    }
    // フェニック木の機能
    // [I] に Xを加算
    private void FenwickTree_Add(long pI, long pX)
    {
        while (pI <= mBitArr.GetUpperBound(0)) {
            mBitArr[pI] += pX;
            pI += pI & -pI;
        }
    }
}
#endregion
            
            
            
        