#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> f(n + 1, n + 1);
for(int i = 1; i <= n; i++) {
int current = 0;
for(int j = i; j <= n; j++) {
current = __gcd(current, a[j]);
if(current == 1) {
f[i] = j;
break;
}
}
}
while(q--) {
int type;
cin >> type;
if(type == 1) {
int index, value;
cin >> index >> value;
a[index] = value;
int c = 0;
int idx = - 1;
for(int j = index; j >= 1; j--) {
c = __gcd(c, a[j]);
if(c == 1) {
idx = j;
break;
}
}
if(idx != - 1) {
for(int j = 1; j <= idx; j++) {
f[j] = min(f[j], index);
}
}
c = 0;
for(int j = index; j <= n; j++) {
c = __gcd(c, a[j]);
if(c == 1) {
f[index] = j;
break;
}
}
}
else {
int l, r;
cin >> l >> r;
int ans = 0;
for(int i = l; i <= r; i++) {
ans += max(0LL, min(r + 1, f[i]) - i);
}
cout << ans << "\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |