QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#775887#9543. Good Partitionschenjue#ML 0ms7728kbC++142.0kb2024-11-23 16:58:462024-11-23 16:58:46

Judging History

你现在查看的是最新测评结果

  • [2024-11-23 16:58:46]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:7728kb
  • [2024-11-23 16:58:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i,l,r) for(int i=l;i<=r;i++) 
#define dep(i,l,r) for(int i=r;i>=l;i--) 
const int N=2e5+10;
using pii=array<int,2>;
int gcdv[N*4];
int b[N*4];
int a[N*4];

void build(int o,int l,int r){
	if(l==r){
		gcdv[o]=b[l];
	}
	else{
		int mid=l+r>>1;
		build(o*2,l,mid);
		build(o*2+1,mid+1,r);
		gcdv[o]=__gcd(gcdv[o*2],gcdv[o*2+1]);
	}
} 
void update(int o,int l,int r,int yl,int yr,int v){
	if(yl<=l&&r<=yr){
		gcdv[o]=v;
	}
	else{
		int mid=l+r>>1;
		if(yl<=mid){
			update(o*2,l,mid,yl,yr,v);
		}
		if(mid<yr){
			update(o*2+1,mid+1,r,yl,yr,v);
		}
		gcdv[o]=__gcd(gcdv[o*2],gcdv[o*2+1]);
	}
}
int query(int o,int l,int r,int yl,int yr){
	int ans=0;
	if(yl<=l&&r<=yr){
		ans=__gcd(ans,gcdv[o]);
	}
	else{
		int mid=l+r>>1;
		if(yl<=mid){
			ans=__gcd(ans,query(o*2,l,mid,yl,yr));
		}
		if(mid<yr){
			ans=__gcd(ans,query(o*2+1,mid+1,r,yl,yr));
		}
	}
	return ans;
}
int check(int d){
	int ans=1;
	for(int j=2;j<=d;j++){
		while(d%j==0){
			ans++;
			d/=j;
		}
	}
	return ans;
}
void solve(){
	int n,m;cin>>n>>m;
	int last=-1e9;
	rep(i,1,n){
		cin>>a[i];
		if(a[i]<last){
			b[i-1]=i-1;
		}
		else{
			b[i-1]=0;
		}
		last=a[i];
	}
	b[n]=0;
	build(1,1,n);
	cout<<check(query(1,1,n,1,n))<<endl;
	a[n+1]=2e9+10;
	rep(i,1,m){
		int x,v;cin>>x>>v;
		a[x]=v;
		if(a[x-1]<=a[x]&&a[x]<=a[x+1]){
			update(1,1,n,x,x,0);
			update(1,1,n,x-1,x-1,0);
		}
		else if(a[x-1]<=a[x]&&a[x]>a[x+1]){
			update(1,1,n,x,x,x);
			update(1,1,n,x-1,x-1,0);
		}
		else if(a[x-1]>a[x]&&a[x]<=a[x+1]){
			update(1,1,n,x,x,0);
			update(1,1,n,x-1,x-1,x-1);
		}
		else if(a[x-1]>a[x]&&a[x]>a[x+1]){
			update(1,1,n,x,x,x);
			update(1,1,n,x-1,x-1,x-1);
		}
		
		update(1,1,n,n,n,0);
		int d=query(1,1,n,1,n);
		int ans=check(d);
		
		cout<<ans<<endl;
	}
	
}
signed main(){
	int _=1;
	cin>>_;
	while(_--)solve(); 
	return 0;
} 
/*
1
5 2
4 3 2 6 1
2 5
3 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7728kb

input:

1
5 2
4 3 2 6 1
2 5
3 5

output:

1
2
3

result:

ok 3 lines

Test #2:

score: -100
Memory Limit Exceeded

input:

1
1 1
2000000000
1 1999999999

output:

1

result: