CF1542D.Priority Queue

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a sequence AA, where its elements are either in the form + x or -, where xx is an integer.

For such a sequence SS where its elements are either in the form + x or -, define f(S)f(S) as follows:

  • iterate through SS's elements from the first one to the last one, and maintain a multiset TT as you iterate through it.
  • for each element, if it's in the form + x, add xx to TT; otherwise, erase the smallest element from TT (if TT is empty, do nothing).
  • after iterating through all SS's elements, compute the sum of all elements in TT. f(S)f(S) is defined as the sum.

The sequence bb is a subsequence of the sequence aa if bb can be derived from aa by removing zero or more elements without changing the order of the remaining elements. For all AA's subsequences BB, compute the sum of f(B)f(B), modulo 998 244 353998\,244\,353.

给你一个序列 AA,其中每个元素的形式为 \+ x 或 -,其中 xx 是一个整数。

对于一个序列 SS(其每个元素的形式同样为 \+ x 或 -),定义函数 f(S)f(S) 如下:

  • 从第一个元素开始,依次遍历 SS 的所有元素,并在遍历过程中维护一个多重集合 TT;
  • 对于每个元素:
    • 若其形式为 \+ x,则将 xx 加入 TT;
    • 若其形式为 -,则从 TT 中删除最小的元素(若 TT 为空,则不执行任何操作);
  • 遍历完 SS 的所有元素后,计算 TT 中所有元素的和;该和即为 f(S)f(S) 的值。

若序列 bb 可通过从序列 aa 中删除零个或多个元素(不改变剩余元素的相对顺序)得到,则称 bb 是 aa 的一个子序列。
对 AA 的所有子序列 BB,求 ∑f(B)\sum f(B) 的值,并对 998 244 353998\,244\,353 取模。

输入格式

The first line contains an integer nn (1≤n≤5001\leq n\leq 500) — the length of AA.

Each of the next nn lines begins with an operator + or -. If the operator is +, then it's followed by an integer xx (1≤x<998 244 3531\le x \lt 998\,244\,353). The ii-th line of those nn lines describes the ii-th element in AA.

第一行包含一个整数 nn(1≤n≤5001\leq n\leq 500)—— 表示数组 AA 的长度。

接下来的 nn 行,每行以操作符 + 或 - 开头。若操作符为 +,则其后跟随一个整数 xx(1≤x<998 244 3531\le x \lt 998\,244\,353)。这 nn 行中的第 ii 行描述了数组 AA 的第 ii 个元素。

输出格式

Print one integer, which is the answer to the problem, modulo 998 244 353998\,244\,353.

输出一个整数,即该问题的答案对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    4
    -
    + 1
    + 2
    -

    输出#1

    16
  • 输入#2

    15
    + 2432543
    -
    + 4567886
    + 65638788
    -
    + 578943
    -
    -
    + 62356680
    -
    + 711111
    -
    + 998244352
    -
    -

    输出#2

    750759115

说明/提示

In the first example, the following are all possible pairs of BB and f(B)f(B):

  • B=B= {}, f(B)=0f(B)=0.
  • B=B= {-}, f(B)=0f(B)=0.
  • B=B= {+ 1, -}, f(B)=0f(B)=0.
  • B=B= {-, + 1, -}, f(B)=0f(B)=0.
  • B=B= {+ 2, -}, f(B)=0f(B)=0.
  • B=B= {-, + 2, -}, f(B)=0f(B)=0.
  • B=B= {-}, f(B)=0f(B)=0.
  • B=B= {-, -}, f(B)=0f(B)=0.
  • B=B= {+ 1, + 2}, f(B)=3f(B)=3.
  • B=B= {+ 1, + 2, -}, f(B)=2f(B)=2.
  • B=B= {-, + 1, + 2}, f(B)=3f(B)=3.
  • B=B= {-, + 1, + 2, -}, f(B)=2f(B)=2.
  • B=B= {-, + 1}, f(B)=1f(B)=1.
  • B=B= {+ 1}, f(B)=1f(B)=1.
  • B=B= {-, + 2}, f(B)=2f(B)=2.
  • B=B= {+ 2}, f(B)=2f(B)=2.

The sum of these values is 1616.

在第一个例子中,以下是所有可能的 BB 与 f(B)f(B) 的组合:

  • B=B= {},f(B)=0f(B)=0。
  • B=B= {-},f(B)=0f(B)=0。
  • B=B= {+ 1, -},f(B)=0f(B)=0。
  • B=B= {-, + 1, -},f(B)=0f(B)=0。
  • B=B= {+ 2, -},f(B)=0f(B)=0。
  • B=B= {-, + 2, -},f(B)=0f(B)=0。
  • B=B= {-},f(B)=0f(B)=0。
  • B=B= {-, -},f(B)=0f(B)=0。
  • B=B= {+ 1, + 2},f(B)=3f(B)=3。
  • B=B= {+ 1, + 2, -},f(B)=2f(B)=2。
  • B=B= {-, + 1, + 2},f(B)=3f(B)=3。
  • B=B= {-, + 1, + 2, -},f(B)=2f(B)=2。
  • B=B= {-, + 1},f(B)=1f(B)=1。
  • B=B= {+ 1},f(B)=1f(B)=1。
  • B=B= {-, + 2},f(B)=2f(B)=2。
  • B=B= {+ 2},f(B)=2f(B)=2。

这些值的总和为 1616。

输入解题思路,AI测评打分。不知道怎么写?

首页