Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<vector>
- #include<map>
- #include<iterator>
- #include<math.h>
- #include<algorithm>
- using namespace std;
- #define mod 1000000007
- int a[1000004] = { 0 };
- long long int BIT[1000004] = { 0 };
- int n;
- int gcd(int a, int b)
- {
- if (a == 0 || b == 0)
- return 0;
- if (a == b)
- return a;
- if (a > b)
- return gcd(a - b, b);
- return gcd(a, b - a);
- }
- void insert(int val,int x){
- int sum = 0;
- for (int i = 1; i <= val; ++i) {
- sum += gcd(i, val);
- if (sum >= mod)
- sum = sum - mod;
- }
- for (; x <= n; x += x & (-x)) {
- BIT[x] += sum;
- if (BIT[x] >= mod)
- BIT[x] = BIT[x] % mod;
- }
- }
- long long int query(int x) {
- long long int sum = 0;
- for (; x > 0; x -= x & (-x))
- sum += BIT[x];
- return sum;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int n,q;
- cin >> n;
- for (int i = 1; i <= n; i++) {
- cin >> a[i];
- insert(a[i], i);
- }
- cin >> q;
- while (q--) {
- char c;
- int l, r;
- cin >> c >> l >>r;
- if (c == 'C'){
- cout << query(r) - query(l - 1) << endl;
- }
- else {
- insert(r - a[l], l);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment