CF348C.Subset Sums

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array a1,a2,...,ana_{1},a_{2},...,a_{n} and mm sets S1,S2,...,SmS_{1},S_{2},...,S_{m} of indices of elements of this array. Let's denote Sk=Sk,i (1<=i<=Sk)S_{k}={S_{k,i}} (1<=i<=|S_{k}|) . In other words, Sk,iS_{k,i} is some element from set SkS_{k} .

In this problem you have to answer qq queries of the two types:

  1. Find the sum of elements with indices from set SkS_{k} : . The query format is "? k".
  2. Add number xx to all elements at indices from set SkS_{k} : aSk,ia_{Sk,i} is replaced by aSk,i+xa_{Sk,i}+x for all ii (1<=i<=Sk)(1<=i<=|S_{k}|) . The query format is "+ k x".

After each first type query print the required sum.

输入格式

The first line contains integers n,m,qn,m,q (1<=n,m,q<=105)(1<=n,m,q<=10^{5}) . The second line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} (ai<=108)(|a_{i}|<=10^{8}) — elements of array aa .

Each of the following mm lines describes one set of indices. The kk -th line first contains a positive integer, representing the number of elements in set ( Sk|S_{k}| ), then follow Sk|S_{k}| distinct integers Sk,1,Sk,2,...,Sk,SkS_{k,1},S_{k,2},...,S_{k,|Sk}| (1<=Sk,i<=n)(1<=S_{k,i}<=n) — elements of set SkS_{k} .

The next qq lines contain queries. Each query looks like either "? k" or "+ k x" and sits on a single line. For all queries the following limits are held: 1<=k<=m1<=k<=m , x<=108|x|<=10^{8} . The queries are given in order they need to be answered.

It is guaranteed that the sum of sizes of all sets SkS_{k} doesn't exceed 10510^{5} .

输出格式

After each first type query print the required sum on a single line.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输入输出样例

  • 输入#1

    5 3 5
    5 -5 5 1 -4
    2 1 2
    4 2 1 4 5
    2 2 5
    ? 2
    + 3 4
    ? 1
    + 2 1
    ? 2
    

    输出#1

    -3
    4
    9
    
首页