QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745753 | #9543. Good Partitions | P3KO | WA | 1ms | 7732kb | C++17 | 1.6kb | 2024-11-14 11:23:25 | 2024-11-14 11:23:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
typedef long long ll;
ll n,q,a[MAXN],d[MAXN];
ll gcd(ll x,ll y){
return y==0?x:gcd(y,x%y);
}
struct seg{
ll g;
}tr[MAXN*4];
void pushup(int p){
tr[p].g=gcd(tr[p<<1].g,tr[p<<1|1].g);
}
void build(int p,int l,int r){
if(l==r){
tr[p]={d[l]};
return;
}
int mid=l+r>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
pushup(p);
}
void insert(int p,int l,int r,int tag,ll v){
if(l==r){
tr[p].g=v;
return;
}
int mid=l+r>>1;
if(tag<=mid)insert(p<<1,l,mid,tag,v);
else insert(p<<1|1,mid+1,r,tag,v);
pushup(p);
}
int query(int p,int s,int t,int l,int r){
if(s>=l&&t<=r)return tr[p].g;
int mid=s+t>>1;
ll ans=0;
if(l<=mid)ans=gcd(query(p<<1,s,mid,l,r),ans);
if(r>mid)ans=gcd(query(p<<1|1,mid+1,t,l,r),ans);
return ans;
}
void input(){
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
}
int numfac(ll x){
int ans=1;
for(int i=2;x>1;i++){
int cnt=0;
if(x%i==0)
while(x%i==0)x/=i,cnt++;
ans*=(cnt+1);
}
return ans;
}
void solve(){
input();
if(n==1){cout<<1<<"\n";return;}
for(int i=1;i<n;i++){
if(a[i+1]<a[i])d[i]=i;
else d[i]=0;
}
n--;
build(1,1,n);
cout<<numfac(query(1,1,n,1,n))<<"\n";
for(int i=1;i<=q;i++){
int p,v;cin>>p>>v;
a[p]=v;
if(p>1){
if(a[p]>=a[p-1])insert(1,1,n,p-1,0);
else insert(1,1,n,p-1,p-1);
}
if(p<=n){
if(a[p]<=a[p+1])insert(1,1,n,p,0);
else insert(1,1,n,p,p);
}
cout<<numfac(query(1,1,n,1,n))<<"\n";
}
}
int main(){
int t;cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7732kb
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
Wrong Answer
time: 1ms
memory: 5736kb
input:
1 1 1 2000000000 1 1999999999
output:
1
result:
wrong answer 2nd lines differ - expected: '1', found: ''