A7992 | Mushroom Gnomes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighboring ones.
The mushroom gnomes loved it when everything was in order, that's why they always planted the mushrooms in one line in the order of their weights' increasing. Well... The gnomes planted the mushrooms and went to eat. After $x$ minutes they returned and saw that new mushrooms had grown up, so that the increasing order had been violated. The gnomes replanted all the mushrooms in the correct order, that is, they sorted the mushrooms in the order of the weights' increasing. And went to eat again (those gnomes were quite big eaters). What total weights modulo $p$ will the mushrooms have in another $y$ minutes?
The mushroom gnomes loved it when everything was in order, that's why they always planted the mushrooms in one line in the order of their weights' increasing. Well... The gnomes planted the mushrooms and went to eat. After $x$ minutes they returned and saw that new mushrooms had grown up, so that the increasing order had been violated. The gnomes replanted all the mushrooms in the correct order, that is, they sorted the mushrooms in the order of the weights' increasing. And went to eat again (those gnomes were quite big eaters). What total weights modulo $p$ will the mushrooms have in another $y$ minutes?
输入格式
## 输入格式
The first line contains four integers $n$ , $x$ , $y$ , $p$ ( $1\leq n \leq 10^{6},0\leq x,y\leq 10^{18},x+y \gt0,2\leq p\leq 10^{9}$ ) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains $n$ integers $a_{i}$ which represent the mushrooms' weight in the non-decreasing order ( $0\leq a_{i}\leq 10^{9}$ ).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
The first line contains four integers $n$ , $x$ , $y$ , $p$ ( $1\leq n \leq 10^{6},0\leq x,y\leq 10^{18},x+y \gt0,2\leq p\leq 10^{9}$ ) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains $n$ integers $a_{i}$ which represent the mushrooms' weight in the non-decreasing order ( $0\leq a_{i}\leq 10^{9}$ ).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
输出格式
The answer should contain a single number which is the total weights of the mushrooms modulo $p$ in the end after $x+y$ minutes.
输入输出样例
输入 #1
2 1 0 657276545 1 2
输出 #1
6
输入 #2
2 1 1 888450282 1 2
输出 #2
14
输入 #3
4 5 0 10000 1 2 3 4
输出 #3
1825
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted