大厂笔试题
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.

40 lines
894 B

  1. /*小美拿到了一个数组,她每次操作会将除了第x个元素的其余元素翻倍,一共操作了q次。请你帮小美计算操作结束后所有元素之和。
  2. 1e9+7
  3. 4 2
  4. 1 2 3 4
  5. 1 2
  6. 34
  7. */
  8. #include <iostream>
  9. #include <vector>
  10. using namespace std;
  11. int main() {
  12. int n;
  13. int val,q,xi;
  14. long sum=0;
  15. const int MOD = 1e9 + 7;
  16. cin >> n;
  17. cin>>q;
  18. vector<int> aa;
  19. vector<int> bb;
  20. for(int i = 0;i < n; i++){
  21. cin>>val;
  22. aa.push_back(val);
  23. bb.push_back(val);
  24. }
  25. for(int i = 0; i < q; i++){
  26. cin>>xi;
  27. xi--;
  28. for(int j = 0; j < n; j++){
  29. if(j == xi)continue;
  30. else{
  31. bb[j] = bb[j] * 2 % MOD;
  32. }
  33. }
  34. }
  35. for(int i = 0; i < bb.size(); i++)sum+=bb[i];
  36. std::cout<<sum % MOD;
  37. return 0;
  38. }