QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744239#9543. Good PartitionsLonelyperWA 100ms12232kbC++202.8kb2024-11-13 21:16:252024-11-13 21:16:27

Judging History

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

  • [2024-11-13 21:16:27]
  • 评测
  • 测评结果:WA
  • 用时:100ms
  • 内存:12232kb
  • [2024-11-13 21:16:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10, M = 1e6 + 10;

int n, q;
int g[N], a[N], tree[N << 2];
int h[M];

LL gcd(LL a, LL b) {
    return b ? gcd(b, a % b) : a;
}

void init2(){
    for(int i = 1; i < M; i ++){
        for(int j = i; j < M; j += i){
            h[j] ++;
        }
    }
}

void init(){
    for(int i = 0; i <= n ; i ++) g[i] = 0;
    for(int i = 0; i <= 4 * n; i ++) tree[i] = 0;
}

void push_up(int p) {
    tree[p] = gcd(tree[p << 1], tree[p << 1 | 1]);
}

void build(int p, int pl, int pr) {
    if (pl == pr) {
        tree[p] = g[pl];
        return;
    }
    int mid = (pl + pr) >> 1;
    build(p << 1, pl, mid);
    build(p << 1 | 1, mid + 1, pr);
    push_up(p);
}

int query(int l, int r, int p, int pl, int pr) {
    if (l <= pl && pr <= r) return tree[p];
    int mid = (pl + pr) >> 1;
    LL res = 0;
    if (l <= mid) res = gcd(res, query(l, r, p << 1, pl, mid));
    if (r > mid) res = gcd(res, query(l, r, p << 1 | 1, mid + 1, pr));
    return res;
}

void update(int pos) {
    if (pos > 1) {
        if (a[pos - 1] > a[pos]) g[pos - 1] = pos - 1;
        else g[pos - 1] = 0;
    }
    if (pos < n) {
        if (a[pos] > a[pos + 1]) g[pos] = pos;
        else g[pos] = 0;
    }
}

void update_tree(int pos, int p, int pl, int pr) {
    if (pl == pr) {
        tree[p] = g[pl];
        return;
    }
    int mid = (pl + pr) >> 1;
    if (pos <= mid) update_tree(pos, p << 1, pl, mid);
    else update_tree(pos, p << 1 | 1, mid + 1, pr);
    push_up(p);
}

void solve() {
    cin >> n >> q;
    init();
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        if (a[i] > a[i + 1]) g[i] = i;
        else g[i] = 0;
    }
    if(n == 1){
        cout << 1 << endl;
        for(int i = 1; i <= q; i ++){
            int p, x;
            cin >> p >> x;
            cout << 1 << endl;
        }
        return;
    }
    build(1, 1, n - 1);
    // cout << tree[1] << ' ';
    int x = query(1, n - 1, 1, 1, n - 1);
    cout << h[x] << endl;
    // cout << h[1] << ' ' << h[2] << ' ' << h[4] << endl;
    while (q--) {
        int pos, x;
        cin >> pos >> x;
        a[pos] = x;
        if (pos > 1) {
            update(pos - 1);
            update_tree(pos - 1, 1, 1, n - 1);
        }
        if (pos < n) {
            update(pos);
            update_tree(pos, 1, 1, n - 1);
        }
        // for(int i = 1; i <= n; i ++) cout << g[i] << ' ';
        // cout << endl;
        // cout << tree[1] << ' ';
        x = query(1, n - 1, 1, 1, n - 1);
        cout << h[x] << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    init2();
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 22ms
memory: 11364kb

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: 23ms
memory: 11368kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 100ms
memory: 12232kb

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
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
160
0
...

result:

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