题目:
拿到一个数组,每次操作会将除了第x个元素之外的元素都翻倍,一共操作q次,求操作结束后所有元素之和
int main() {
int n, q, xi;
const long long mod = 1e9 + 7;
cin >> n >> q;
vector<long long> a(n);
vector<long long> mul2(q, 2);
unordered_map<int, int> notmul;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
//构建快速二次幂
for (int i = 1; i < q; i++) {
mul2[i] = mul2[i-1] * 2 % mod;
}
for (int i = 0; i < q; i++) {;
cin >> xi;
notmul[xi - 1]++;
}
int ans = 0;
for (int i = 0; i < n; i++) {
int tmp = a[i] * mul2[q - 1 - notmul[i]] % mod; //每个元素乘以对应的倍数(mul2[q-1]表示翻倍了q次,减去没有被翻倍的次数得到实际被翻倍次数)
ans += tmp;
}
cout << ans << endl;
}