A9264 | Subset Sums
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $a_{1},a_{2},...,a_{n}$ and $m$ sets $S_{1},S_{2},...,S_{m}$ of indices of elements of this array. Let's denote $S_{k}={S_{k,i}} (1<=i<=|S_{k}|)$ . In other words, $S_{k,i}$ is some element from set $S_{k}$ .
In this problem you have to answer $q$ queries of the two types:
1. Find the sum of elements with indices from set $S_{k}$ : . The query format is "? k".
2. Add number $x$ to all elements at indices from set $S_{k}$ : $a_{Sk,i}$ is replaced by $a_{Sk,i}+x$ for all $i$ $(1<=i<=|S_{k}|)$ . The query format is "+ k x".
After each first type query print the required sum.
In this problem you have to answer $q$ queries of the two types:
1. Find the sum of elements with indices from set $S_{k}$ : . The query format is "? k".
2. Add number $x$ to all elements at indices from set $S_{k}$ : $a_{Sk,i}$ is replaced by $a_{Sk,i}+x$ for all $i$ $(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,q$ $(1<=n,m,q<=10^{5})$ . The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ $(|a_{i}|<=10^{8})$ — elements of array $a$ .
Each of the following $m$ lines describes one set of indices. The $k$ -th line first contains a positive integer, representing the number of elements in set ( $|S_{k}|$ ), then follow $|S_{k}|$ distinct integers $S_{k,1},S_{k,2},...,S_{k,|Sk}|$ $(1<=S_{k,i}<=n)$ — elements of set $S_{k}$ .
The next $q$ 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<=m$ , $|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 $S_{k}$ doesn't exceed $10^{5}$ .
Each of the following $m$ lines describes one set of indices. The $k$ -th line first contains a positive integer, representing the number of elements in set ( $|S_{k}|$ ), then follow $|S_{k}|$ distinct integers $S_{k,1},S_{k,2},...,S_{k,|Sk}|$ $(1<=S_{k,i}<=n)$ — elements of set $S_{k}$ .
The next $q$ 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<=m$ , $|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 $S_{k}$ doesn't exceed $10^{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.
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted