fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool containsDigit(int x, int d) {
  5. string s = to_string(x);
  6. char c = '0' + d;
  7. for (char ch : s) if (ch == c) return true;
  8. return false;
  9. }
  10.  
  11. int main() {
  12. ios_base::sync_with_stdio(false);
  13. cin.tie(NULL);
  14.  
  15. int n, q;
  16. if (!(cin >> n >> q)) return 0;
  17.  
  18. vector<long long> a(n + 1);
  19. for (int i = 1; i <= n; ++i) cin >> a[i];
  20.  
  21. while (q--) {
  22. int type;
  23. cin >> type;
  24. if (type == 1) {
  25. int p;
  26. long long x;
  27. cin >> p >> x;
  28. if (1 <= p && p <= n) a[p] = x;
  29. } else if (type == 2) {
  30. int l, r, d;
  31. cin >> l >> r >> d;
  32. if (l < 1) l = 1;
  33. if (r > n) r = n;
  34. long long res = 0;
  35. for (int i = l; i <= r; ++i) {
  36. bool isValid = false;
  37. if (d != 0) {
  38. if (i % d == 0) isValid = true;
  39. }
  40. if (!isValid && containsDigit(i, d)) isValid = true;
  41.  
  42. if (isValid) res += 2LL * a[i];
  43. else res += a[i];
  44. }
  45. cout << res << '\n';
  46. }
  47. }
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty