結果
問題 | No.1996 <>< |
ユーザー |
|
提出日時 | 2023-09-28 00:04:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 214 ms / 2,000 ms |
コード長 | 2,774 bytes |
コンパイル時間 | 1,212 ms |
コンパイル使用メモリ | 116,080 KB |
実行使用メモリ | 41,728 KB |
最終ジャッジ日時 | 2024-07-20 18:28:14 |
合計ジャッジ時間 | 5,770 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList;; var n = c[0]; var a = Compress(NList); var s = ReadLine(); var dp = Enumerable.Repeat(1L, n).ToArray(); var mod = 1_000_000_007; for (var i = 0; i < s.Length; ++i) { var ndp = new long[n]; var ft = new FenwickTree(n + 1); for (var j = 0; j < n; ++j) { if (s[i] == '<') ndp[j] = ft.Sum(a[j] - 1) % mod; else ndp[j] = (ft.Sum(n) - ft.Sum(a[j])) % mod; ft.Add(a[j], dp[j]); } dp = ndp; } var ans = 0L; for (var i = 0; i < n; ++i) ans = (ans + dp[i]) % mod; WriteLine(ans); } static int[] Compress(int[] a) { var list = new List<int>(new HashSet<int>(a)); list.Sort(); var dic = new Dictionary<int, int>(); for (var i = 0; i < list.Count; ++i) dic[list[i]] = i + 1; var ans = new int[a.Length]; for (var i = 0; i < a.Length; ++i) ans[i] = dic[a[i]]; return ans; } class FenwickTree { int size; long[] tree; public FenwickTree(int size) { this.size = size; tree = new long[size + 2]; } public void Add(int index, long value) { ++index; for (var x = index; x <= size; x += (x & -x)) tree[x] += value; } /// <summary>先頭からindexまでの和(include index)</summary> public long Sum(int index) { ++index; var sum = 0L; for (var x = index; x > 0; x -= (x & -x)) sum += tree[x]; return sum; } /// <summary>Sum(x) >= value となる最小のxを求める</summary> // 各要素は非負であること public int LowerBound(long value) { if (value < 0) return -1; var x = 0; var b = 1; while (b * 2 <= size) b <<= 1; for (var k = b; k > 0; k >>= 1) { if (x + k <= size && tree[x + k] < value) { value -= tree[x + k]; x += k; } } return x; } } }