結果
問題 | No.686 Uncertain LIS |
ユーザー | 紙ぺーぱー |
提出日時 | 2018-05-12 00:39:45 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 282 ms / 2,000 ms |
コード長 | 11,465 bytes |
コンパイル時間 | 1,213 ms |
コンパイル使用メモリ | 118,320 KB |
実行使用メモリ | 37,088 KB |
最終ジャッジ日時 | 2024-05-08 00:29:17 |
合計ジャッジ時間 | 8,231 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
26,960 KB |
testcase_01 | AC | 28 ms
26,960 KB |
testcase_02 | AC | 28 ms
24,576 KB |
testcase_03 | AC | 30 ms
27,028 KB |
testcase_04 | AC | 28 ms
24,916 KB |
testcase_05 | AC | 29 ms
25,212 KB |
testcase_06 | AC | 27 ms
25,052 KB |
testcase_07 | AC | 28 ms
26,992 KB |
testcase_08 | AC | 27 ms
25,172 KB |
testcase_09 | AC | 243 ms
34,408 KB |
testcase_10 | AC | 233 ms
34,400 KB |
testcase_11 | AC | 155 ms
32,616 KB |
testcase_12 | AC | 33 ms
25,008 KB |
testcase_13 | AC | 91 ms
29,160 KB |
testcase_14 | AC | 122 ms
30,960 KB |
testcase_15 | AC | 88 ms
31,200 KB |
testcase_16 | AC | 198 ms
31,320 KB |
testcase_17 | AC | 268 ms
33,116 KB |
testcase_18 | AC | 278 ms
37,088 KB |
testcase_19 | AC | 274 ms
35,052 KB |
testcase_20 | AC | 243 ms
31,464 KB |
testcase_21 | AC | 242 ms
29,284 KB |
testcase_22 | AC | 141 ms
28,780 KB |
testcase_23 | AC | 137 ms
31,096 KB |
testcase_24 | AC | 175 ms
31,972 KB |
testcase_25 | AC | 176 ms
30,052 KB |
testcase_26 | AC | 228 ms
37,088 KB |
testcase_27 | AC | 182 ms
31,976 KB |
testcase_28 | AC | 178 ms
31,868 KB |
testcase_29 | AC | 181 ms
31,980 KB |
testcase_30 | AC | 181 ms
31,860 KB |
testcase_31 | AC | 29 ms
24,828 KB |
testcase_32 | AC | 213 ms
34,912 KB |
testcase_33 | AC | 226 ms
37,088 KB |
testcase_34 | AC | 276 ms
32,996 KB |
testcase_35 | AC | 282 ms
35,056 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; //using System.Numerics; using static System.Math; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var n = ri; var seg = new BalancedTree(); seg.Insert(0, 0); seg.Insert(1, 1000000000); /* n = 75; var dp = new long[100]; //*/ for (int i = 0; i < n; i++) { var l = ri; var r = ri; /* var l = rnd.Next(1, 100); var r = rnd.Next(1, 100); if (l > r) Swap(ref l, ref r); for (int j = r; j >= l; j--) dp[j] = Math.Max(dp[j], dp[j - 1] + 1); for (int j = 1; j < 100; j++) dp[j] = Math.Max(dp[j], dp[j - 1]); //*/ var lb = seg.tree.root.LowerBound(l, Comparer<long>.Default); var rb = seg.tree.root.LowerBound(r, Comparer<long>.Default); //Debug.WriteLine($"{l} {r} {lb} {rb}"); if (lb != rb) { seg.Push(lb, rb, 1); seg.RemoveAt(rb); seg.Insert(lb, l); } else { seg.RemoveAt(lb); seg.Insert(lb, l); } Debug.WriteLine(seg.Items.AsJoinedString()); } var a = seg.Items; Debug.WriteLine(a.AsJoinedString()); for (int i = a.Length - 1; i >= 0; i--) if (a[i] != 1000000000) { Console.WriteLine(i); break; } //Debug.WriteLine(dp.Max()); } const long INF = 5L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer: StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region Balanced Tree public class BalancedTree { public AVLTree<Node> tree = new AVLTree<Node>(); public int Count { get { return tree.Count; } } public void Push(int l, int r, long v) { push(tree.root, l, r, v); } Node push(Node n, int l, int r, long v) { if (n.cnt == 0) return n; n = n.Push(); if (l <= 0 && n.cnt <= r) { n.Add += v; n.Update(); return n; } else { if (0 < r && l < n.lst.cnt) n.lst = push(n.lst, l, r, v); if (n.lst.cnt + 1 < r && l < n.cnt) n.rst = push(n.rst, l - n.lst.cnt - 1, r - n.lst.cnt - 1, v); if (l <= n.lst.cnt && n.lst.cnt < r) n.Key += v; n.Update(); return n; } } public long Query(int l, int r) { return query(tree.root, l, r); } long query(Node n, int l, int r) { n = n.Push(); if (l <= 0 && n.cnt <= r) { return n.Key; } else { if (0 < r && l < n.lst.cnt) return query(n.lst, l, r); else if (n.lst.cnt + 1 < r && l < n.cnt) return query(n.rst, l - n.lst.cnt - 1, r - n.lst.cnt - 1); else return n.Key; } } public bool Insert(int lb, long item) { var v = new Node() { Key = item }; tree.Insert(v, lb); return true; } public bool RemoveAt(int k) { if (k < 0 || k >= Count) return false; tree.RemoveAt(k); return true; } public long this[int index] { get { if (index < 0 || index >= Count) throw new IndexOutOfRangeException(); var t = tree.Find(tree.root, index); return t.Key; } } public long[] Items { get { var ret = new long[Count]; int ptr = 0; walk(tree.root, ret, ref ptr); return ret; } } void walk(Node root, long[] a, ref int ptr) { if (root.cnt == 0) return; walk(root.lst, a, ref ptr); a[ptr++] = root.Key; walk(root.rst, a, ref ptr); } public class Node: AVLTreeNode<Node>, IKey<long> { public long Key { get; set; } public long Add { get; set; } public override Node Push() { if (lst.cnt != 0) lst.Add += Add; if (rst.cnt != 0) rst.Add += Add; Key += Add; Add = 0; return this; } } } #endregion #region AVLTree public abstract class AVLTreeNode<T>: BinaryTreeNode<T> where T : AVLTreeNode<T> { public int rank; public override void Update() { cnt = 1 + lst.cnt + rst.cnt; rank = 1 + Math.Max(lst.rank, rst.rank); } } public class AVLTree<T>: Tree<T> where T : AVLTreeNode<T>, new() { public override void Insert(T v, int k) { root = insert(root, v, k); NIL.cnt = 0; } public override void RemoveAt(int k) { root = removeat(root, k); NIL.cnt = 0; } T insert(T t, T v, int k) { t = t.Push(); if (t.cnt == 0) { v.lst = v.rst = NIL; v.Update(); return v; } if (t.lst.cnt >= k) t.lst = insert(t.lst, v, k); else t.rst = insert(t.rst, v, k - t.lst.cnt - 1); if (t.lst.rank - t.rst.rank == -2) { if (t.rst.lst.rank > t.rst.rst.rank) t.rst = rotR(t.rst); t = rotL(t); } else if (t.lst.rank - t.rst.rank == 2) { if (t.lst.lst.rank < t.lst.rst.rank) t.lst = rotL(t.lst); t = rotR(t); } else t.Update(); t.Update(); return t; } T removeat(T t, int k) { t = t.Push(); var cnt = t.lst.cnt; if (cnt < k) t.rst = removeat(t.rst, k - cnt - 1); else if (cnt > k) t.lst = removeat(t.lst, k); else { if (cnt == 0) return t.rst; if (t.rst.cnt == 0) return t.lst; var next = Find(t.lst, k - 1); next = next.Push(); next.lst = removeat(t.lst, k - 1); next.rst = t.rst; t = next; } if (t.lst.rank - t.rst.rank == -2) { if (t.rst.lst.rank > t.rst.rst.rank) t.rst = rotR(t.rst); t = rotL(t); } else if (t.lst.rank - t.rst.rank == 2) { if (t.lst.lst.rank < t.lst.rst.rank) t.lst = rotL(t.lst); t = rotR(t); } else t.Update(); return t; } } #endregion #region BinaryTree public interface IKey<K> { K Key { get; set; } } public abstract class BinaryTreeNode<T> where T : BinaryTreeNode<T> { public int cnt; public T lst, rst; public abstract T Push(); public abstract void Update(); } public abstract class Tree<TNode> where TNode : BinaryTreeNode<TNode>, new() { public Tree() { NIL = new TNode(); NIL.lst = NIL; NIL.rst = NIL; root = NIL; } public readonly TNode NIL; public TNode root; public int Count { get { return root.cnt; } } protected TNode rotR(TNode t) { t = t.Push(); var l = t.lst.Push(); t.lst = l.rst; l.rst = t; t.Update(); l.Update(); return l; } protected TNode rotL(TNode t) { t = t.Push(); var r = t.rst.Push(); t.rst = r.lst; r.lst = t; r.lst = t; t.Update(); r.Update(); return r; } public TNode Find(TNode t, int k) { t = t.Push(); if (k < t.lst.cnt) return Find(t.lst, k); else if (k > t.lst.cnt) return Find(t.rst, k - t.lst.cnt - 1); else return t; } public abstract void Insert(TNode v, int k); public abstract void RemoveAt(int k); } public static class TreeOperation { static public int LowerBound<T, K> (this T t, K k, IComparer<K> cmp) where T : BinaryTreeNode<T>, IKey<K> { if (t.cnt == 0) return 0; t = t.Push(); if (cmp.Compare(k, t.Key) <= 0) return LowerBound(t.lst, k, cmp); else return 1 + t.lst.cnt + LowerBound(t.rst, k, cmp); } static public int UpperBound<T, K> (this T t, K k, IComparer<K> cmp) where T : BinaryTreeNode<T>, IKey<K> { if (t.cnt == 0) return 0; t = t.Push(); if (cmp.Compare(t.Key, k) <= 0) return 1 + t.lst.cnt + UpperBound(t.rst, k, cmp); else return UpperBound(t.lst, k, cmp); } } #endregion