QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725600#9543. Good PartitionslxlTL 1ms3808kbC++201.8kb2024-11-08 19:00:512024-11-08 19:00:52

Judging History

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

  • [2024-11-08 19:00:52]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3808kb
  • [2024-11-08 19:00:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n,q;
int countFactors(int n) {
	unordered_map<int, int> primeFactors; // 存储质因数和对应的指数
	int original = n;
	
	// 处理 2 的因数
	while (n % 2 == 0) {
		primeFactors[2]++;
		n /= 2;
	}
	
	// 处理奇数因数
	for (int i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			primeFactors[i]++;
			n /= i;
		}
	}
	
	// 如果 n 是一个质数且大于 2
	if (n > 2) {
		primeFactors[n]++;
	}
	
	// 计算因数个数
	int factorCount = 1;
	for (const auto& pair : primeFactors) {
		factorCount *= (pair.second + 1);
	}
	
	return factorCount;
}
void out(set<int> st){
	int g = 0;
	for(auto k : st){
		if(!g) g = k;
		else g = __gcd(g,k);
//		cout<<"k = "<<k<<" g = "<<g<<endl;
	}
	int ans = countFactors(g);
//	cout<<"ans.size :"<<ans.size()<<endl;
//	for(auto k : ans){
//		cout<<k<<" ";
//	}
//	cout<<endl;
	if(g == n){
		cout<<n<<'\n';
		return;
	}
	if(ans) cout<<ans<<'\n';
	else cout<<n<<'\n';
}
void solve(){
	cin>>n>>q;
	vector<int> a(n+1);
	set<int> st;
	for(int i = 1;i <= n;i++) cin>>a[i];
	int st1 = a[1];
	for(int i = 1;i <= n;i++){
		if(i != 1 && a[i] < st1){
			st.insert(i-1);
		}
		st1 = a[i];
	}
//	for(auto k : st){
//		cout<<"k = "<<k<<endl;
//	}
	out(st);
	for(int i = 1;i <= q;i++){
		int p,val;cin>>p>>val;
		a[p] = val;
		if(a[p-1] <= a[p]){
			if(st.count(p-1)) st.erase(p-1);
			if(a[p+1] >= a[p]){
				if(st.count(p)) st.erase(p);
			}else{
				st.insert(p);
			}
		}else{
			st.insert(p-1);
			if(a[p] <= a[p+1]){
				if(st.count(p)) st.erase(p);
			}else{
				st.insert(p);
			}
		}
		
//		for(auto k : st){
//			cout<<"k = "<<k<<endl;
//		}
		out(st);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t = 1;
	cin>>t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3808kb

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
Time Limit Exceeded

input:

1
1 1
2000000000
1 1999999999

output:


result: