結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー | AreTrash |
提出日時 | 2018-06-09 00:07:38 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,360 bytes |
コンパイル時間 | 1,289 ms |
コンパイル使用メモリ | 117,912 KB |
実行使用メモリ | 47,488 KB |
最終ジャッジ日時 | 2024-06-30 11:28:20 |
合計ジャッジ時間 | 5,747 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | AC | 47 ms
19,968 KB |
testcase_06 | AC | 49 ms
19,712 KB |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 45 ms
25,608 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.IO; using System.Collections.Generic; using System.Linq; namespace No694_1 { public class Program { void Solve(StreamScanner ss, StreamWriter sw) { //--------------------------------- var N = ss.Next(int.Parse); var A = Compress(ss.Next(long.Parse, N)); var cs = new Dictionary<int, int>(); foreach (var tup in A.OrderBy(x => x).Select((a, i) => (a, i))) { var (a, i) = (tup.Item1, tup.Item2); if (cs.ContainsKey(a)) cs[a]--; else cs.Add(a, N - 2 * i - 1); } var bit = new BinaryIndexedTree(N); var cross = 0; foreach (var tup in A.Select((a, i) => (a, i))) { var (a, i) = (tup.Item1, tup.Item2); cross += i - bit.Sum(a); bit.Add(a, 1); } sw.WriteLine(cross); foreach (var a in A.Take(N - 1)) sw.WriteLine(cross += cs[a]); //--------------------------------- } IEnumerable<int> Compress(IEnumerable<long> source) { var comp = source .OrderBy(x => x) .Select((k, v) => new { k, v }) .ToDictionary(kvp => kvp.k, kvp => kvp.v); return source.Select(x => comp[x] + 1); } static void Main() { var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput())); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; new Program().Solve(ss, sw); sw.Flush(); } static readonly Func<string, string> String = s => s; } public class BinaryIndexedTree { readonly int _size; readonly int[] _bit; public BinaryIndexedTree(int size) { _size = size; _bit = new int[_size + 1]; } public void Add(int x, int w) { for (var i = x; i <= _size; i += i & -i) _bit[i] += w; } public int Sum(int x) { var ret = 0; for (var i = x; i >= 1; i -= i & -i) ret += _bit[i]; return ret; } } public class StreamScanner { static readonly char[] Sep = { ' ' }; readonly Queue<string> buffer = new Queue<string>(); readonly TextReader textReader; public StreamScanner(TextReader textReader) { this.textReader = textReader; } public T Next<T>(Func<string, T> parser) { if (buffer.Count != 0) return parser(buffer.Dequeue()); var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries); foreach (var nextString in nextStrings) buffer.Enqueue(nextString); return Next(parser); } public T[] Next<T>(Func<string, T> parser, int x) { var ret = new T[x]; for (var i = 0; i < x; ++i) ret[i] = Next(parser); return ret; } public T[][] Next<T>(Func<string, T> parser, int x, int y) { var ret = new T[y][]; for (var i = 0; i < y; ++i) ret[i] = Next(parser, x); return ret; } } }