1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=2e5+7, mod=1e9+7;
int tr[N<<2];
int n,q,a[N],x,v,cf[N],phi[N];
void init(int n){
for(int i=1;i<=n;i++){
for(int j=1;j*i<=n;j++){
phi[j*i]++;
}
}
}
void update(int now){
tr[now]=__gcd(tr[ls],tr[rs]);
}
void build(int now,int l,int r){
if(l==r){
if(cf[l]<0){
tr[now]=l;
}
else tr[now]=0;
return;
}
int mid=(l+r)>>1;
build(ls,l,mid);
build(rs,mid+1,r);
update(now);
}
void modify(int now,int l,int r,int val,int pos){
if(l==r){
if(val>=0){
tr[now]=0;
}
else tr[now]=l;
return;
}
int mid=(l+r)>>1;
if(pos<=mid){
modify(ls,l,mid,val,pos);
}
else modify(rs,mid+1,r,val,pos);
update(now);
}
void solve(){
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<n;i++)cf[i]=a[i+1]-a[i];
if(n==1){
cout<<1<<endl;
while(q--){
cin>>x>>v;
cout<<1<<endl;
}
return;
}
build(1,1,n-1);
int ans=abs(tr[1]);
if(n==1||ans==0)cout<<n<<endl;
else cout<<phi[ans]<<endl;
while(q--){
cin>>x>>v;
a[x]=v;
if(x>1)modify(1,1,n-1,a[x]-a[x-1],x-1);
if(x<n)modify(1,1,n-1,a[x+1]-a[x],x);
if(n==1){
cout<<n<<endl;
continue;
}
ans=abs(tr[1]);
if(!ans){
cout<<n<<endl;
}
else cout<<phi[ans]<<endl;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
init(N);
int t=1;
cin>>t;
while(t--)solve();
return 0;
}
|