結果
問題 | No.404 部分門松列 |
ユーザー | りあん |
提出日時 | 2016-05-10 01:01:39 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,060 bytes |
コンパイル時間 | 2,339 ms |
コンパイル使用メモリ | 114,388 KB |
実行使用メモリ | 68,476 KB |
最終ジャッジ日時 | 2024-11-06 08:11:04 |
合計ジャッジ時間 | 12,770 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 37 ms
26,940 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; class Program { static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var sc = new Scan(); int n = sc.Int; var a = sc.IntArr; var b = new int[n]; var ar = a.ToList().Distinct().ToArray(); Array.Sort(ar); int lim = ar.Length; var zip = new SortedDictionary<int, int>(); for (int i = 0; i < lim; i++) zip.Add(ar[i], i); var sgbef = new Segtree<long>(lim, (i, j) => i + j, 0); var sgaft = new Segtree<long>(lim, (i, j) => i + j, 0); var sgmul = new Segtree<long>(lim, (i, j) => i + j, 0); for (int i = 0; i < n; i++) { b[i] = zip[a[i]]; sgaft.update(b[i], sgaft.look(b[i]) + 1); } long ans = 0; for (int i = 0; i < n; i++) { sgaft.update(b[i], sgaft.look(b[i]) - 1); sgmul.update(b[i], sgbef.look(b[i]) * sgaft.look(b[i])); ans += sgbef.run(0, b[i] - 1) * sgaft.run(0, b[i] - 1) - sgmul.run(0, b[i] - 1) + sgbef.run(b[i] + 1, lim) * sgaft.run(b[i] + 1, lim) - sgmul.run(b[i] + 1, lim); sgbef.update(b[i], sgbef.look(b[i]) + 1); sgmul.update(b[i], sgbef.look(b[i]) * sgaft.look(b[i])); } sw.WriteLine(ans); sw.Flush(); } } class Scan { public int Int { get { return int.Parse(Console.ReadLine().Trim()); } } public long Long { get { return long.Parse(Console.ReadLine().Trim()); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); } } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ini; for (int i = 0; i < m; ++i) update(i, ini); } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public T look(int i) { return tree[i + n - 1]; } // [s, t] public T run(int s, int t) { return query(s, t + 1, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } }