Universal Cup Judging System

Universal Cup

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓
统计

ローマ数字の以下のような一般化を考えます。全部で $n$ 個の数字(文字)があり、各数字は独自の優先度と値を持っています。この問題では、これらのローマ数字を英小文字および英大文字からなる文字列で表します。$i$ 番目のローマ数字の優先度、値、文字列表現をそれぞれ $p_i$、$v_i$、$d_i$ と表すことにします。

ローマ数字における数とは、ローマ数字からなる配列のことです。数 $d_1 \dots d_m$ の値は再帰的に計算されます。まず、数字 $d_i$ の優先度が最も高くなるような位置 $i$ を選びます。最も高い優先度を持つ数字が複数ある場合は、その中で位置 $i$ が最も小さいものを選びます。このとき、

$$\operatorname{value}(d_1 \dots d_m) = v_i - \operatorname{value}(d_1 \dots d_{i-1}) + \operatorname{value}(d_{i+1} \dots d_m),$$

となります。ここで $v_i$ は $d_i$ の値です。空の数の値は慣例により $0$ とします。

例えば、三つ組 $(p_i, v_i, d_i)$ として $(1, 1, \texttt{I})$、$(2, 5, \texttt{V})$、$(3, 10, \texttt{X})$ を考えます。これらは通常のローマ数字に通常の値を割り当てます。例えば、$\operatorname{value}(\texttt{II}) = 2$、$\operatorname{value}(\texttt{IX}) = 9$、$\operatorname{value}(\texttt{XIV}) = 14$ となります。一方で、表現は一意ではなくなります。例えば $\operatorname{value}(\texttt{IXI}) = \operatorname{value}(\texttt{IIIIIXV}) = \operatorname{value}(\texttt{X}) = 10$ です。

ローマ数字からなる配列 $s_1 \dots s_n$ と、$(\ell, r)$ の形をした $q$ 個の独立なクエリが与えられます。各クエリについて、部分配列 $s_\ell \dots s_r$ の値を計算してください。

入力

最初の行には 3 つの整数 $m$、$n$、$q$($1 \le m \le 10^5$、$1 \le n, q \le 3 \cdot 10^5$)が与えられます。これらはそれぞれローマ数字の種類数、与えられる配列の長さ、クエリの個数を表します。

続いて $m$ 行が与えられます。そのうち $i$ 番目の行には 2 つの整数 $p_i$ と $v_i$($1 \le p_i \le m$、$1 \le v_i \le 10^9$)、およびそれに続く英小文字・英大文字からなる文字列 $d_i$($1 \le |d_i| \le 7$)が含まれます。これらはそれぞれ $i$ 番目のローマ数字の優先度、値、文字列表現です。すべての $d_i$ は互いに異なります。

次の行には、空白で区切られた $n$ 個のローマ数字の表現 $s_1 \dots s_n$ が与えられます。

続いて $q$ 行が与えられ、各行には 2 つの整数 $\ell$ と $r$($1 \le \ell \le r \le n$)が含まれます。

出力

各クエリについて、数 $s_\ell \dots s_r$ の値を表す 1 つの整数を 1 行に出力してください。

入出力例

入力 1

3 5 3
1 1 I
2 5 V
3 10 X
I X I V X
1 2
1 3
3 5

出力 1

9
10
6

入力 2

3 6 1
1 6 six
1 16 sixteen
1 60 sixty
six sixty six sixteen six sixteen
1 6

出力 2

110

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.