QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#725600 | #9543. Good Partitions | lxl | TL | 1ms | 3808kb | C++20 | 1.8kb | 2024-11-08 19:00:51 | 2024-11-08 19:00:52 |
Judging History
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