CF1542D.Priority Queue

普及/提高-

通过率:0%

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 998244353998\,244\,353 .

输入格式

The first line contains an integer nn ( 1n5001\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 ( 1x<9982443531\le x<998\,244\,353 ). The ii -th line of those nn lines describes the ii -th element in AA .

输出格式

Print one integer, which is the answer to the problem, modulo 998244353998\,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 .

首页