結果
問題 |
No.3039 配信者
|
ユーザー |
![]() |
提出日時 | 2025-03-02 17:12:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,195 bytes |
コンパイル時間 | 4,157 ms |
コンパイル使用メモリ | 118,424 KB |
実行使用メモリ | 26,020 KB |
最終ジャッジ日時 | 2025-03-02 17:12:19 |
合計ジャッジ時間 | 9,484 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | TLE * 1 -- * 14 |
コンパイルメッセージ
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/3039 class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("3 5"); WillReturn.Add("0 2"); WillReturn.Add("1 4"); WillReturn.Add("2 3"); } else if (InputPattern == "Input2") { WillReturn.Add("7 10"); WillReturn.Add("8 9"); WillReturn.Add("3 6"); WillReturn.Add("2 4"); WillReturn.Add("1 8"); WillReturn.Add("7 9"); WillReturn.Add("0 4"); WillReturn.Add("5 6"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); long[] wkArr = { }; Action<string> SplitAct = pStr => wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray(); SplitAct(InputList[0]); long H = wkArr[1]; var InsDualSegmentTree = new DualSegmentTree(H); foreach (string EachStr in InputList.Skip(1)) { SplitAct(EachStr); long A = wkArr[0]; long B = wkArr[1]; InsDualSegmentTree.RangeAdd(A, B, 1); } long Answer = 0; for (long I = 0; I <= H; I++) { Answer = Math.Max(Answer, InsDualSegmentTree[I]); } Console.WriteLine(Answer); } } // 区間加算、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