QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734725#9543. Good PartitionsXiaoretaWWA 95ms10252kbC++202.7kb2024-11-11 14:37:332024-11-11 14:37:34

Judging History

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

  • [2024-11-11 14:37:34]
  • 评测
  • 测评结果:WA
  • 用时:95ms
  • 内存:10252kb
  • [2024-11-11 14:37:33]
  • 提交

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 >= 1){
            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 << max(1, a) << '\n';
}

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

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

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6096kb

input:

1
5 2
4 3 2 6 1
2 5
3 5

output:

1
2
3

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 5380kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 95ms
memory: 10252kb

input:

1
200000 200000
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
160
1
...

result:

wrong answer 2nd lines differ - expected: '200000', found: '1'