Guest User

Untitled

a guest
Jun 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<vector>
  4. #include<map>
  5. #include<iterator>
  6. #include<math.h>
  7. #include<algorithm>
  8.  
  9. using namespace std;
  10. #define mod 1000000007
  11.  
  12. int a[1000004] = { 0 };
  13. long long int BIT[1000004] = { 0 };
  14. int n;
  15.  
  16. int gcd(int a, int b)
  17. {
  18. if (a == 0 || b == 0)
  19. return 0;
  20.  
  21. if (a == b)
  22. return a;
  23.  
  24. if (a > b)
  25. return gcd(a - b, b);
  26. return gcd(a, b - a);
  27. }
  28.  
  29. void insert(int val,int x){
  30.  
  31. int sum = 0;
  32.  
  33. for (int i = 1; i <= val; ++i) {
  34.  
  35. sum += gcd(i, val);
  36. if (sum >= mod)
  37. sum = sum - mod;
  38.  
  39. }
  40.  
  41. for (; x <= n; x += x & (-x)) {
  42. BIT[x] += sum;
  43. if (BIT[x] >= mod)
  44. BIT[x] = BIT[x] % mod;
  45. }
  46. }
  47.  
  48.  
  49. long long int query(int x) {
  50.  
  51. long long int sum = 0;
  52. for (; x > 0; x -= x & (-x))
  53. sum += BIT[x];
  54. return sum;
  55. }
  56.  
  57. int main()
  58. {
  59. ios_base::sync_with_stdio(false);
  60. cin.tie(NULL);
  61.  
  62. int n,q;
  63. cin >> n;
  64.  
  65. for (int i = 1; i <= n; i++) {
  66. cin >> a[i];
  67. insert(a[i], i);
  68. }
  69.  
  70. cin >> q;
  71.  
  72. while (q--) {
  73. char c;
  74. int l, r;
  75. cin >> c >> l >>r;
  76.  
  77. if (c == 'C'){
  78.  
  79. cout << query(r) - query(l - 1) << endl;
  80.  
  81. }
  82. else {
  83.  
  84. insert(r - a[l], l);
  85.  
  86. }
  87.  
  88. }
  89.  
  90. return 0;
  91. }
Add Comment
Please, Sign In to add comment