QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#772214#9543. Good PartitionsZycK#WA 26ms9308kbC++143.7kb2024-11-22 17:35:032024-11-22 17:35:04

Judging History

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

  • [2024-11-22 17:35:04]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:9308kb
  • [2024-11-22 17:35:03]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i, l, r) for (int i=l; i<=r; ++i)
#define ls(p) ((p)<<1)
#define rs(p) ((p)<<1|1)
using namespace std;
template <typename T>
inline void read(T &x) {
    char c = getchar(); int w = 1; x = 0;
    while (!isdigit(c))
        (c == '-') && (w = -w), c = getchar();
    while (isdigit(c))
        x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
    x *= w;
}

const int N = 200010;
int n, q, j, v, ans[N], a[N], len[N], g[N<<2];
set<int> S;
inline int gcd(int x, int y) {
    return !y ? x : gcd(y, x % y);
}
inline void push_up(int p) {
    g[p] = gcd(g[ls(p)], g[rs(p)]);
}
inline void update(int l, int r, int p, int x, int v) {
    if (l == r) {
        len[x] += v;
        g[p] = len[x] ? x : 0;
        return;
    }
    int mid = l+r >> 1;
    if (x <= mid) update(l, mid, ls(p), x, v);
    if (x >  mid) update(mid+1, r, rs(p), x, v);
    push_up(p);
}
inline void build(int l, int r, int p) {
    if (l == r) {
        g[p] = len[l] ? l : 0; return;
    }
    int mid = l+r >> 1;
    build(l, mid, ls(p));
    build(mid+1, r, rs(p));
    push_up(p);
}
inline void add(int x) {
    if (x < *S.begin()) {
        int y = *S.begin();
        if (y == n+1) {
            update(1, n, 1, x-1, 1);
        }
        else {
            update(1, n, 1, y-1, -1);
            update(1, n, 1, x-1, 1);
            update(1, n, 1, y-x, 1);
        }
    }
    else {
        auto it = S.lower_bound(x);
        int y = *(--it);
        if (*it == n+1) {
            update(1, n, 1, x-y, 1);
        }
        else {
            update(1, n, 1, (*it)-y, -1);
            update(1, n, 1, x-y, 1);
            update(1, n, 1, (*it)-x, 1);
        }
    }
    S.insert(x);
}
inline void del(int x) {
    if (x == *S.begin()) {
        auto it = S.begin();
        ++ it;
        int y = *it;
        if (y == n+1) {
            update(1, n, 1, x-1, -1);
        }
        else {
            update(1, n, 1, x-1, -1);
            update(1, n, 1, y-x, -1);
            update(1, n, 1, y-1, 1);
        }
    }
    else {
        auto it = S.lower_bound(x);
        int y = *(--it);
        if (*it == n+1) {
            update(1, n, 1, x-y, -1);
        }
        else {
            update(1, n, 1, (*it)-x, -1);
            update(1, n, 1, x-y, -1);
            update(1, n, 1, (*it)-y, 1);
        }
    }
    S.erase(x);
}
signed main() {
    int T;
    For(i, 1, 200000) {
        for (int j=i; j<=200000; j+=i) {
            ans[j] ++;
        }
    }
    read(T);
    while (T -- > 0) {
        read(n); read(q);
        For(i, 1, n) {
            len[i] = 0;
        }
        int lst = 1;
        a[0] = 0;
        S.clear();
        S.insert(n+1);
        For(i, 1, n) {
            read(a[i]);
            if (a[i]-a[i-1] < 0) {
                len[i-lst] += 1;
                lst = i;
                S.insert(i);
            }
        }
        build(1, n, 1);
        // cout << g[1] << endl;
        if (*S.begin() == n+1) printf("%d\n", n);
        else printf("%d\n", ans[g[1]]);
        while (q -- > 0) {
            read(j); read(v);
            if (a[j]-a[j-1] >= 0 && v-a[j-1] < 0) {
                add(j);
            }
            if (a[j]-a[j-1] < 0 && v-a[j-1] >= 0) {
                del(j);
            }
            if (j+1 <= n && a[j+1]-a[j] >= 0 && a[j+1]-v < 0) {
                add(j+1);
            }
            if (j+1 <= n && a[j+1]-a[j] < 0 && a[j+1]-v >= 0) {
                del(j+1);
            }
            if (*S.begin() == n+1) printf("%d\n", n);
            else printf("%d\n", ans[g[1]]);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 7904kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 26ms
memory: 9308kb

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

result:

wrong answer 3rd lines differ - expected: '160', found: '200000'