結果

問題 No.2422 regisys?
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-09 13:28:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 668 ms / 2,000 ms
コード長 3,688 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 66,712 KB
実行使用メモリ 58,480 KB
最終ジャッジ日時 2023-10-09 13:29:11
合計ジャッジ時間 18,465 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
21,924 KB
testcase_01 AC 70 ms
21,852 KB
testcase_02 AC 80 ms
23,944 KB
testcase_03 AC 72 ms
24,036 KB
testcase_04 AC 79 ms
22,032 KB
testcase_05 AC 71 ms
21,764 KB
testcase_06 AC 78 ms
24,036 KB
testcase_07 AC 71 ms
21,896 KB
testcase_08 AC 71 ms
23,948 KB
testcase_09 AC 70 ms
19,760 KB
testcase_10 AC 71 ms
21,768 KB
testcase_11 AC 71 ms
21,892 KB
testcase_12 AC 69 ms
21,952 KB
testcase_13 AC 78 ms
21,968 KB
testcase_14 AC 78 ms
24,156 KB
testcase_15 AC 72 ms
23,964 KB
testcase_16 AC 80 ms
22,136 KB
testcase_17 AC 70 ms
22,020 KB
testcase_18 AC 79 ms
24,192 KB
testcase_19 AC 77 ms
22,200 KB
testcase_20 AC 78 ms
19,988 KB
testcase_21 AC 70 ms
22,044 KB
testcase_22 AC 72 ms
21,924 KB
testcase_23 AC 79 ms
24,056 KB
testcase_24 AC 77 ms
22,140 KB
testcase_25 AC 77 ms
22,016 KB
testcase_26 AC 69 ms
21,900 KB
testcase_27 AC 71 ms
23,992 KB
testcase_28 AC 72 ms
21,768 KB
testcase_29 AC 81 ms
22,004 KB
testcase_30 AC 71 ms
21,908 KB
testcase_31 AC 252 ms
45,156 KB
testcase_32 AC 354 ms
42,836 KB
testcase_33 AC 234 ms
42,704 KB
testcase_34 AC 223 ms
35,904 KB
testcase_35 AC 272 ms
45,432 KB
testcase_36 AC 282 ms
42,496 KB
testcase_37 AC 362 ms
45,032 KB
testcase_38 AC 306 ms
42,140 KB
testcase_39 AC 228 ms
37,500 KB
testcase_40 AC 182 ms
36,896 KB
testcase_41 AC 220 ms
36,376 KB
testcase_42 AC 414 ms
51,816 KB
testcase_43 AC 272 ms
39,712 KB
testcase_44 AC 446 ms
54,420 KB
testcase_45 AC 393 ms
50,452 KB
testcase_46 AC 443 ms
54,288 KB
testcase_47 AC 311 ms
47,100 KB
testcase_48 AC 451 ms
57,044 KB
testcase_49 AC 383 ms
47,080 KB
testcase_50 AC 412 ms
58,480 KB
testcase_51 AC 599 ms
54,004 KB
testcase_52 AC 237 ms
45,400 KB
testcase_53 AC 443 ms
54,444 KB
testcase_54 AC 623 ms
57,088 KB
testcase_55 AC 447 ms
55,332 KB
testcase_56 AC 459 ms
47,896 KB
testcase_57 AC 637 ms
57,636 KB
testcase_58 AC 654 ms
57,736 KB
testcase_59 AC 649 ms
57,696 KB
testcase_60 AC 668 ms
57,672 KB
testcase_61 AC 70 ms
23,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var a = NList;
        var b = NList;
        var map = NArr(m);
        var list = new List<(int id, int b)>(n);
        for (var i = 0; i < n; ++i) list.Add((i, b[i]));
        list.Sort((l, r) => r.b.CompareTo(l.b));
        var mmas = new List<int>();
        var ppls = new List<int>();
        for (var i = 0; i < m; ++i)
        {
            if (map[i][0] == 0) ppls.Add(map[i][1]);
            else mmas.Add(map[i][1]);
        }
        mmas.Sort();
        ppls.Sort();
        var q = new PriorityQueue<int>(n, true);
        var ans = n;
        for (var i = 0; i < mmas.Count; ++i)
        {
            while (list.Count > 0 && list[list.Count - 1].b <= mmas[i])
            {
                q.Enqueue(a[list[list.Count - 1].id]);
                list.RemoveAt(list.Count - 1);
            }
            if (q.Count > 0)
            {
                q.Dequeue();
                --ans;
            }
        }
        var rest = new List<int>(list.Select(li => a[li.id]));
        while (q.Count > 0) rest.Add(q.Dequeue());
        rest.Sort((l, r) => r.CompareTo(l));
        for (var i = 0; i < ppls.Count; ++i)
        {
            if (rest.Count > 0 && rest[rest.Count - 1] <= ppls[i])
            {
                --ans;
                rest.RemoveAt(rest.Count - 1);
            }
        }
        WriteLine(ans);
    }
    class PriorityQueue<T> where T : IComparable<T>
    {
        public T[] List;
        public int Count;
        bool IsTopMax;
        public PriorityQueue(int count, bool isTopMax)
        {
            IsTopMax = isTopMax;
            List = new T[Math.Max(128, count)];
        }
        public void Enqueue(T value)
        {
            if (Count == List.Length)
            {
                var newlist = new T[List.Length * 2];
                for (var i = 0; i < List.Length; ++i) newlist[i] = List[i];
                List = newlist;
            }
            var pos = Count;
            List[pos] = value;
            ++Count;
            while (pos > 0)
            {
                var parent = (pos - 1) / 2;
                if (Calc(List[parent], List[pos], true)) break;
                Swap(parent, pos);
                pos = parent;
            }
        }
        public T Dequeue()
        {
            --Count;
            Swap(0, Count);
            var pos = 0;
            while (true)
            {
                var child = pos * 2 + 1;
                if (child >= Count) break;
                if (child + 1 < Count && Calc(List[child + 1], List[child], false)) ++child;
                if (Calc(List[pos], List[child], true)) break;
                Swap(pos, child);
                pos = child;
            }
            return List[Count];
        }
        bool Calc(T a, T b, bool equalVal)
        {
            var ret = a.CompareTo(b);
            if (ret == 0 && equalVal) return true;
            return IsTopMax ? ret > 0 : ret < 0;
        }
        void Swap(int a, int b)
        {
            var tmp = List[a];
            List[a] = List[b];
            List[b] = tmp;
        }
    }
}
0