結果
問題 | No.686 Uncertain LIS |
ユーザー | 紙ぺーぱー |
提出日時 | 2018-05-12 00:08:59 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 297 ms / 2,000 ms |
コード長 | 11,182 bytes |
コンパイル時間 | 2,630 ms |
コンパイル使用メモリ | 117,660 KB |
実行使用メモリ | 29,312 KB |
最終ジャッジ日時 | 2024-05-08 00:28:54 |
合計ジャッジ時間 | 9,909 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
18,944 KB |
testcase_01 | AC | 29 ms
18,944 KB |
testcase_02 | AC | 29 ms
18,816 KB |
testcase_03 | AC | 29 ms
18,944 KB |
testcase_04 | AC | 29 ms
18,944 KB |
testcase_05 | AC | 29 ms
18,560 KB |
testcase_06 | AC | 30 ms
18,816 KB |
testcase_07 | AC | 29 ms
18,944 KB |
testcase_08 | AC | 29 ms
18,944 KB |
testcase_09 | AC | 255 ms
26,240 KB |
testcase_10 | AC | 242 ms
26,240 KB |
testcase_11 | AC | 161 ms
24,320 KB |
testcase_12 | AC | 35 ms
19,584 KB |
testcase_13 | AC | 94 ms
23,124 KB |
testcase_14 | AC | 125 ms
22,952 KB |
testcase_15 | AC | 91 ms
22,912 KB |
testcase_16 | AC | 198 ms
22,912 KB |
testcase_17 | AC | 288 ms
26,880 KB |
testcase_18 | AC | 289 ms
26,880 KB |
testcase_19 | AC | 291 ms
27,008 KB |
testcase_20 | AC | 248 ms
23,552 KB |
testcase_21 | AC | 251 ms
23,424 KB |
testcase_22 | AC | 143 ms
22,912 KB |
testcase_23 | AC | 146 ms
22,912 KB |
testcase_24 | AC | 184 ms
24,064 KB |
testcase_25 | AC | 182 ms
23,808 KB |
testcase_26 | AC | 240 ms
28,800 KB |
testcase_27 | AC | 185 ms
23,808 KB |
testcase_28 | AC | 186 ms
23,808 KB |
testcase_29 | AC | 188 ms
23,808 KB |
testcase_30 | AC | 190 ms
23,680 KB |
testcase_31 | AC | 29 ms
18,944 KB |
testcase_32 | AC | 225 ms
28,800 KB |
testcase_33 | AC | 243 ms
29,312 KB |
testcase_34 | AC | 297 ms
26,880 KB |
testcase_35 | AC | 291 ms
26,752 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; Set seg = new Set(); seg.Insert(0, 0); seg.Insert(1000000000, 1); /* 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.LowerBound(l); var rb = seg.LowerBound(r); //Debug.WriteLine($"{l} {r} {lb} {rb}"); if (lb != rb) { seg.Add(lb, rb, 1); seg.RemoveAt(rb); seg.Insert(l, lb); } else { seg.RemoveAt(lb); seg.Insert(l, lb); } //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 Set public class Set { AVLTree<Node> tree = new AVLTree<Node>(); IComparer<long> cmp = Comparer<long>.Default; public bool IsMultiSet { get; set; } public int Count { get { return tree.Count; } } public bool Insert(long item, int lb) { var v = new Node() { Key = item }; tree.Insert(v, lb); return true; } public void Add(int l, int r, long v) { add(tree.root, l, r, v); } Node add(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 = add(n.lst, l, r, v); if (n.lst.cnt + 1 < r && l < n.cnt) n.rst = add(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 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 int LowerBound(long item) { return tree.root.LowerBound(item, cmp); } public int UpperBound(long item) { return tree.root.UpperBound(item, cmp); } public long[] Items { get { var ret = new long[Count]; int ptr = 0; walk(tree.root, ret, ref ptr); return ret; } } public bool IsReadOnly { get { return false; } } 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); } 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