QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725458#9543. Good PartitionsKiritoXDML 3ms6536kbC++201.7kb2024-11-08 17:56:462024-11-08 17:56:46

Judging History

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

  • [2024-11-08 17:56:46]
  • 评测
  • 测评结果:ML
  • 用时:3ms
  • 内存:6536kb
  • [2024-11-08 17:56:46]
  • 提交

answer

#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];
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 6536kb

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:


result: