コード例 #1
0
ファイル: 1381269.cs プロジェクト: qifanyyy/CLCDSA
        public void Solve()
        {
            var       n   = ri;
            var       w   = Enumerate(n, x => rl);
            const int T   = 500050;
            var       seg = new StarySkyTree(new long[T]);
            var       Q   = Enumerate(T, x => new List <int>());

            for (int i = 0; i < n; i++)
            {
                var m = ri;
                foreach (var x in sc.Integer(m))
                {
                    Q[x / 2].Add(i);
                }
            }
            //seg.Push(0, 1, w.Sum());
            var max  = 0L;
            var prev = Enumerate(n, x => - 1);

            for (int t = 1; t < T; t++)
            {
                var ma = seg.Query(0, t);
                max = Max(max, ma);
                seg.Push(t, t + 1, ma);
                //Debug.WriteLine(seg.Items.Take(t + 1).Select(x => x - X).AsJoinedString());
                foreach (var i in Q[t])
                {
                    var pre = prev[i];
                    seg.Push(pre + 1, t + 1, w[i]);
                    prev[i] = t;
                }
            }
            IO.Printer.Out.WriteLine(max);
        }
コード例 #2
0
        public void Solve()
        {
            var rand = new Random(0);

            for (int _ = 0; _ < 1; _++)
            {
                var n = ri;
                var m = ri;
                //var n = rand.Next(50, 100);
                //var m = rand.Next(50, 100);
                var A     = Enumerate(m + 5, x => new List <int>());
                var stary = new StarySkyTree(m);
                stary.Push(0, m, 500000);
                for (int i = 0; i < m; i++)
                {
                    stary.Push(i, m, -1);
                }
                var L = new int[n];
                var R = new int[n];
                for (int i = 0; i < n; i++)
                {
                    var l = ri;
                    var r = ri;
                    //var l = rand.Next(0, 40);
                    //var r = rand.Next(m - 40, m + 2);
                    L[i] = l;
                    R[i] = r;
                }
                for (int i = 0; i < n; i++)
                {
                    var l = L[i];
                    var r = R[i];
                    A[l].Add(r);
                    stary.Push(m - r, m, 1);
                }
                var  cnt  = 0;
                var  pqL  = new PriorityQueue <int>();
                long min  = 1000000000;
                var  dame = 0;
                for (int i = 0; i <= m; i++, cnt++)
                {
                    //Debug.WriteLine(stary.Items.Select(x => x - 500000).AsJoinedString());
                    foreach (var x in A[i])
                    {
                        pqL.Enqueue(x);
                        stary.Push(m - x, m, -1);
                    }
                    while (pqL.Count > cnt)
                    {
                        var p = pqL.Dequeue();
                        if (p == m + 1)
                        {
                            dame++;
                        }
                        else
                        {
                            stary.Push(m - p, m, 1);
                        }
                    }
                    var max = Max(0, stary.Query(0, m) - 500000) + dame;
                    min = Min(min, max);
                }
                if (min < n - m)
                {
                    min = n - m;
                }
                IO.Printer.Out.WriteLine(min);
                //var res = debug(L, R, m);
                //Debug.WriteLine(res);
                //if (min != res)
                {
                }
            }
        }