QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#726240#9543. Good Partitionsthe_foolRE 235ms16236kbC++202.9kb2024-11-08 22:30:552024-11-08 22:30:56

Judging History

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

  • [2024-11-08 22:30:56]
  • 评测
  • 测评结果:RE
  • 用时:235ms
  • 内存:16236kb
  • [2024-11-08 22:30:55]
  • 提交

answer

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

using LL = long long;

#define ls (u << 1)
#define rs (u << 1 | 1)

struct segtree {
    int n, p;
    vector<int> g;

    segtree (int _n) {
        n = _n;
        p = __bit_ceil(n + 2);
        g.assign(2 * p + 1, {});
    }

    void pushup(int u) {
        // cerr << "PUSHUP " << u << "\n";
        // cerr << format("g[{}] = gcd(g[{}] = {}, g[{}] = {}) = {}", u, ls, g[ls], rs, g[rs], gcd(g[ls], g[rs])) << "\n";
        g[u] = gcd(g[ls], g[rs]);
    }

    void cg(int u, int v) {
        // assert(u >= 1 and u <= n);
        // int uu = u;
        u += p;
        if (v > int(1E9)) {
            v = 0;
        }
        g[u] = v;
        while (u >>= 1) {
            pushup(u);
        }
        // cerr << "AFTER CG " << uu << " " << v << "\n";
        // show();
        // cerr << "\n";
    }

    // void show() {
    //     cerr << "NOW ALL THE BASE:\n";
    //     for (int i = 1; i <= n; i++) {
    //         cerr << g[i + p] << " \n"[i == n];
    //     }
    //     cerr << "NOW ALL THE TREE:\n";
    //     for (int i = 1; i <= 2 * p; i++) {
    //         cerr << g[i] << " \n"[i == 2 * p];
    //     }
    // }
};

#undef ls
#undef rs

constexpr int inf = 2E9 + 10;
constexpr int N = 2E5 + 10;
int cnt[N];

int init = []() {
    for (int i = 1; i < N; i++) {
        for (int j = i; j < N; j += i) {
            cnt[j]++;
        }
    }
    return 0;
}();


void solve() {
    int n, q;
    cin >> n >> q;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    a.emplace_back(inf);

    set<int> s{0, inf};
    for (int i = 1; i <= n; i++) {
        if (a[i] > a[i + 1]) s.emplace(i);
    }

    segtree tr(n + 1);
    int ls = 0;
    for (int x : s) {
        if (x) {
            tr.cg(ls + 1, x - ls);
            ls = x;
        }
    }

    auto del = [&](int x) {
        auto it = s.find(x);
        if (it == s.end()) return;
        auto it1 = prev(it), it2 = next(it);
        tr.cg(x + 1, 0);
        tr.cg(*it1 + 1, *it2 - *it1);
        s.erase(it);
    };

    auto add = [&](int x) {
        auto it1 = s.lower_bound(x);
        if (*it1 == x) return;
        auto it2 = prev(it1);
        tr.cg(*it2 + 1, x - *it2);
        tr.cg(x + 1, *it1 - x);
        s.emplace(x);
    };

    cout << (tr.g[1] == 0 ? n : cnt[tr.g[1]]) << "\n";
    while (q--) {
        int x, v;
        cin >> x >> v;
        del(x);
        del(x - 1);
        a[x] = v;
        if (a[x] > a[x + 1]) add(x);
        if (a[x - 1] > a[x]) add(x - 1);
        int res = tr.g[1];
        cout << (res == 0 ? n : cnt[res]) << "\n";
        // tr.show();
    }
}

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

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3ms
memory: 4340kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 59ms
memory: 6620kb

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

result:

ok 200001 lines

Test #4:

score: 0
Accepted
time: 235ms
memory: 16236kb

input:

1
200000 200000
200001 200000 199999 199998 199997 199996 199995 199994 199993 199992 199991 199990 199989 199988 199987 199986 199985 199984 199983 199982 199981 199980 199979 199978 199977 199976 199975 199974 199973 199972 199971 199970 199969 199968 199967 199966 199965 199964 199963 199962 1999...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200001 lines

Test #5:

score: 0
Accepted
time: 61ms
memory: 6632kb

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:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 200001 lines

Test #6:

score: 0
Accepted
time: 3ms
memory: 4628kb

input:

2
2 2
17017 63462
2 94054
2 13504
8 8
14380 5840 34752 73602 60279 26105 44308 78318
7 8597
2 70671
6 56663
5 90093
5 96853
3 10700
1 76875
6 27325

output:

2
2
1
1
1
1
1
1
1
1
1
1

result:

ok 12 lines

Test #7:

score: -100
Runtime Error

input:

10
9 15
850456 510799 912572 938543 215712 758501 850577 149454 330027
7 740992
7 73826
1 993823
7 143019
8 152824
2 109975
5 151989
7 851016
3 157534
8 491512
6 987473
7 272348
3 842756
4 278214
5 707564
10 17
494099 922564 124251 422938 100551 915266 18436 74858 885629 897256
8 798574
7 49544
7 83...

output:


result: