結果
問題 | No.318 学学学学学 |
ユーザー | eitaho |
提出日時 | 2016-01-08 01:34:52 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 250 ms / 2,000 ms |
コード長 | 4,319 bytes |
コンパイル時間 | 2,864 ms |
コンパイル使用メモリ | 116,332 KB |
実行使用メモリ | 54,080 KB |
最終ジャッジ日時 | 2024-06-22 16:16:49 |
合計ジャッジ時間 | 7,664 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
29,732 KB |
testcase_01 | AC | 68 ms
31,008 KB |
testcase_02 | AC | 75 ms
32,544 KB |
testcase_03 | AC | 62 ms
29,344 KB |
testcase_04 | AC | 71 ms
30,260 KB |
testcase_05 | AC | 240 ms
52,420 KB |
testcase_06 | AC | 223 ms
50,260 KB |
testcase_07 | AC | 172 ms
49,052 KB |
testcase_08 | AC | 146 ms
47,592 KB |
testcase_09 | AC | 131 ms
47,280 KB |
testcase_10 | AC | 116 ms
44,548 KB |
testcase_11 | AC | 250 ms
54,080 KB |
testcase_12 | AC | 187 ms
48,616 KB |
testcase_13 | AC | 163 ms
49,140 KB |
testcase_14 | AC | 148 ms
45,644 KB |
testcase_15 | AC | 137 ms
45,484 KB |
testcase_16 | AC | 127 ms
45,952 KB |
testcase_17 | AC | 162 ms
47,080 KB |
testcase_18 | AC | 156 ms
49,868 KB |
testcase_19 | AC | 150 ms
49,288 KB |
testcase_20 | AC | 110 ms
38,860 KB |
testcase_21 | AC | 33 ms
25,756 KB |
testcase_22 | AC | 34 ms
25,648 KB |
testcase_23 | AC | 33 ms
25,508 KB |
testcase_24 | AC | 34 ms
27,820 KB |
testcase_25 | AC | 35 ms
25,536 KB |
testcase_26 | AC | 34 ms
27,828 KB |
testcase_27 | AC | 34 ms
27,684 KB |
testcase_28 | AC | 34 ms
25,396 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.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; class Program { public void Solve() { int N = Reader.Int(); var A = Reader.IntArray(N); var L = new Dictionary<int, int>(); var R = new Dictionary<int, int>(); for (int i = 0; i < N; i++) R[A[i]] = i; for (int i = N - 1; i >= 0; i--) L[A[i]] = i; var seg = new RangeUpdateSumSegTree(N); foreach (int val in A.Distinct().OrderBy(a => a)) seg.Update(L[val], R[val] + 1, val); var ans = Enu.Range(0, N).Select(i => seg.Sum(i, i + 1)); Console.WriteLine(string.Join(" ", ans)); } class RangeUpdateSumSegTree { public readonly int N; private readonly int[] V, S; private readonly bool[] Flag; public RangeUpdateSumSegTree(int n) { for (N = 4; N < n; ) N *= 2; V = new int[N * 2]; S = new int[N * 2]; Flag = new bool[N * 2]; } public int Sum(int L, int R) { return Sum(0, 0, N, L, R); } private int Sum(int i, int currL, int currR, int L, int R) { if (currL >= R || currR <= L) return 0; if (currL >= L && currR <= R) return S[i]; if (Flag[i]) return V[i] * (Math.Min(currR, R) - Math.Max(currL, L)); int mid = (currL + currR) / 2; int valL = Sum(i * 2 + 1, currL, mid, L, R); int valR = Sum(i * 2 + 2, mid, currR, L, R); return valL + valR; } public void Update(int L, int R, int val) { Update(0, val, 0, N, L, R); } private void Update(int i, int val, int currL, int currR, int L, int R) { if (currL >= R || currR <= L) return; if (currL >= L && currR <= R) { Flag[i] = true; V[i] = val; S[i] = val * (currR - currL); return; } if (Flag[i] && currR - currL > 1) { V[i * 2 + 1] = V[i * 2 + 2] = V[i]; S[i * 2 + 1] = S[i * 2 + 2] = (currR - currL) / 2 * V[i]; Flag[i * 2 + 1] = Flag[i * 2 + 2] = true; Flag[i] = false; } int mid = (currL + currR) / 2; Update(i * 2 + 1, val, currL, mid, L, R); Update(i * 2 + 2, val, mid, currR, L, R); S[i] = S[i * 2 + 1] + S[i * 2 + 2]; } } } class Entry { static void Main() { new Program().Solve(); } } class Reader { private static TextReader reader = Console.In; private static readonly char[] separator = { ' ' }; private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; private static string[] A = new string[0]; private static int i; private static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); } public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); } public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Next()).ToArray(); } public static string Line() { return reader.ReadLine().Trim(); } private static string[] Split(string s) { return s.Split(separator, op); } private static string Next() { CheckNext(); return A[i++]; } private static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }