QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734721#9543. Good PartitionsXiaoretaWRE 3ms7616kbC++202.7kb2024-11-11 14:35:382024-11-11 14:35:39

Judging History

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

  • [2024-11-11 14:35:39]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:7616kb
  • [2024-11-11 14:35:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define vi vector<int>
#define fi first
#define se second
#define ll long long
#define pb push_back
#define pii pair<ll, int>
#define all(a) a.begin(), a.end()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define per(i,b,a) for(int i = b-;1 i >= a; --i)

const int N = 200010;
int tr[4*N];
void update(int p){
    tr[p] = gcd(tr[p*2], tr[p*2+1]);
}
void build(int p, int l, int r){
    if(l == r){
        tr[p] = 0;
        return;
    }
    int mid = (l + r) >> 1;
    build(p*2, l, mid);
    build(p*2+1, mid+1, r);
    update(p);
}
void change(int p, int l, int r, int pos, int val){
    if(l == r){
        assert(l == pos);
        tr[p] = val;
        return;
    }
    int mid = (l + r) >> 1;
    if(pos <= mid) change(p*2, l, mid, pos, val);
    else change(p*2+1, mid+1, r, pos, val);
    update(p);
}
int query(){
    return tr[1];
}
int prime[N];
bool m[N];
int pn[N];
int minp[N];
int pcnt=0;

void sift(){
    pn[1]=1;
    for(int i=2;i<N;i++){
        if(!m[i]){
            pn[i]=2;
            prime[pcnt++]=i;
            minp[i]=i;
        }
        for(int j=0;prime[j]<=(N-1)/i;j++){
            m[i*prime[j]]=1;
            minp[i*prime[j]]=prime[j];
            if(i%prime[j]){
                pn[i*prime[j]]=pn[i]*2;
            }
            else{
                int cnt=2;
                int ti=i;
                while(ti%minp[i]==0){
                    ti/=minp[i];
                    cnt++;
                }
                pn[i*prime[j]]=pn[ti]*cnt;
                break;
            }
        }
    }
}


void solve(){
    int n, q; cin >> n >> q;
    build(1, 1, n);
    vi a(n+1); rep(i,1,n+1) cin >> a[i];
    vi g(n+1);
    rep(i,1,n) if(a[i] > a[i+1]){
        g[i] = i;
        change(1, 1, n, i, i);
    }
    vi ans; ans.reserve(q+1);
    ans.pb(pn[query()]);
    while(q--){
        int p, v; cin >> p >> v;
        a[p] = v;
        if(g[p]){
            if(p+1 <= n and a[p] <= a[p+1]){
                g[p] = 0;
                change(1, 1, n, p, 0);
            }
        }else{
            if(p+1 <= n and a[p] > a[p+1]){
                g[p] = p;
                change(1, 1, n, p, p);
            }
        }
        if(p-1 >= 0){
            if(a[p-1] > a[p]){
                g[p-1] = p-1;
                change(1, 1, n, p-1, p-1);
            }else{
                g[p-1] = 0;
                change(1, 1, n, p-1, 0);
            }
        }
        // debug(g, query());
        ans.pb(pn[query()]);
    }
    for(int a: ans) cout << a << '\n';
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);

    sift();
    int T; cin >> T;
    while(T--) solve();

    return 0;
}

详细

Test #1:

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

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
Runtime Error

input:

1
1 1
2000000000
1 1999999999

output:


result: