結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー | AreTrash |
提出日時 | 2018-06-09 00:13:35 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,386 bytes |
コンパイル時間 | 1,014 ms |
コンパイル使用メモリ | 115,072 KB |
実行使用メモリ | 82,380 KB |
最終ジャッジ日時 | 2024-06-30 11:36:49 |
合計ジャッジ時間 | 10,937 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
25,736 KB |
testcase_01 | AC | 46 ms
25,976 KB |
testcase_02 | AC | 47 ms
25,864 KB |
testcase_03 | AC | 48 ms
25,772 KB |
testcase_04 | AC | 48 ms
25,740 KB |
testcase_05 | AC | 48 ms
25,736 KB |
testcase_06 | AC | 49 ms
25,616 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 46 ms
25,740 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 .Distinct() .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; } } }