QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#772666#9543. Good PartitionsyouyouyouML 4ms10192kbC++202.2kb2024-11-22 21:06:512024-11-22 21:06:52

Judging History

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

  • [2024-11-22 21:06:52]
  • 评测
  • 测评结果:ML
  • 用时:4ms
  • 内存:10192kb
  • [2024-11-22 21:06:51]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;
i64 aa[200000+50]={0};
i64 ans[805005],a[205005],yinshu[205005];
i64 gcccd(i64 a,i64 b){
    if(b==0)return a;
    if(a%b==0){
        return b;
    }
    return gcccd(b,a%b);
}
int lc(int p){return p<<1;}
int rc(int p){return p<<1|1;}
void push_up(int p){
    ans[p]=gcccd(ans[lc(p)],ans[rc(p)]);       //查询方式
}
void build(i64 p,i64 l,i64 r)
{   
    if(l==r){ans[p]=a[l];return ;}      //建树,树里是什么
    i64 mid=(l+r)>>1;
    build(lc(p),l,mid);
    build(rc(p),mid+1,r);
    push_up(p);
}
void update(i64 nl,i64 nr,i64 l,i64 r,i64 p,i64 k)
{
    if(nl<=l&&r<=nr)        
    {
        ans[p]=k;
        return ;
    }
    i64 mid=(l+r)>>1;
    if(nl<=mid)update(nl,nr,l,mid,lc(p),k);
    if(nr>mid) update(nl,nr,mid+1,r,rc(p),k);
    push_up(p);
}
void solve()
{
    i64 n,q;
    cin>>n>>q;
   

    for(i64 i=0;i<n+5;i++){
        a[i]=0;
    }
    cin>>aa[1];
    for(i64 i=2;i<=n;i++){
        cin>>aa[i];
        if(aa[i]<aa[i-1]){
            a[i-1]=i-1;
        }else{
            a[i-1]=0;
        }
    }
    build(1,1,n-1);
    n--;
    
    i64 daan=ans[1];
    if(daan==0){
        cout<<1+n<<'\n';
    }else
    cout<<yinshu[daan]<<'\n';
    while(q--){
        i64 p,v;
        cin>>p>>v;
        aa[p]=v;
        if(p<=n){
            if(aa[p]>aa[p+1]){
                a[p]=p;
                update(p,p,1,n,1,p);
            }else{
                a[p]=0;
                update(p,p,1,n,1,0);
            }
        }
        if(p>1){
            if(aa[p-1]>aa[p]){
                a[p-1]=p-1;
                update(p-1,p-1,1,n,1,p-1);
            }else{
                a[p-1]=0;
                update(p-1,p-1,1,n,1,0);
            }
        }
        daan=ans[1];
        if(daan==0){
            cout<<1+n<<'\n';
        }else
        cout<<yinshu[daan]<<'\n';
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for(i64 i=1;i<=200004;i++){
        for(i64 j=i;j<=200004;j+=i){
             yinshu[j]++;
        }
    }
    i64 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: 4ms
memory: 10192kb

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: