大厂笔试题
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
894 B

/*小美拿到了一个数组,她每次操作会将除了第x个元素的其余元素翻倍,一共操作了q次。请你帮小美计算操作结束后所有元素之和。
由于答案过大,请对1e9+7取模。
输入:
4 2
1 2 3 4
1 2
输出:
34
*/
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
int val,q,xi;
long sum=0;
const int MOD = 1e9 + 7;
cin >> n;
cin>>q;
vector<int> aa;
vector<int> bb;
for(int i = 0;i < n; i++){
cin>>val;
aa.push_back(val);
bb.push_back(val);
}
for(int i = 0; i < q; i++){
cin>>xi;
xi--;
for(int j = 0; j < n; j++){
if(j == xi)continue;
else{
bb[j] = bb[j] * 2 % MOD;
}
}
}
for(int i = 0; i < bb.size(); i++)sum+=bb[i];
std::cout<<sum % MOD;
return 0;
}