QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739146#9543. Good PartitionsFoedere0WA 279ms16964kbC++202.6kb2024-11-12 21:01:052024-11-12 21:01:07

Judging History

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

  • [2024-11-12 21:01:07]
  • 评测
  • 测评结果:WA
  • 用时:279ms
  • 内存:16964kb
  • [2024-11-12 21:01:05]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int N = 1000010;
int s[N], a[N], d[N * 4];
int getd(int x)
{
    int res = 0;
    for (int i = 1; i <= x / i; i++)
    {
        if (x % i == 0)
        {
            res++;
            if (i != x / i)
                res++;
        }
    }
    // sort(res.begin(), res.end());
    return res;
}
void pushdown(int p)
{
    if (!d[2 * p] && !d[2 * p + 1])
    {
        d[p] = 0;
    }
    else if (d[2 * p] && !d[2 * p + 1])
    {
        d[p] = d[2 * p];
    }
    else if (!d[2 * p] && d[2 * p + 1])
    {
        d[p] = d[p * 2 + 1];
    }
    else
    {
        d[p] = __gcd(d[p * 2], d[p * 2 + 1]);
    }
}
void build(int s, int t, int p)
{
    // cout << s << " " << t << " " << p << endl;
    if (s == t)
    {
        // cout << p << " " << a[s] << endl;
        d[p] = a[s];
        return;
    }
    int mid = (s + t) >> 1;
    build(s, mid, p * 2), build(mid + 1, t, p * 2 + 1);
    pushdown(p);
}
void chenge(int s, int t, int e, int c, int p)
{
    if (s == t)
    {
        d[p] = c;
        return;
    }
    int mid = (s + t) >> 1;
    if (mid >= e)
        chenge(s, mid, e, c, p * 2);
    else
        chenge(mid + 1, t, e, c, p * 2 + 1);
    pushdown(p);
}
void solve()
{
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        a[i] = 0;
    }
    s[n + 1] = 5e9;
    for (int i = 1; i <= n; i++)
    {
        if (s[i] > s[i + 1])
            a[i] = i;
    }
    // cout << endl;
    build(1, n, 1);
    // cout << d[4] << " **" << d[1] << endl;
    int t = d[1];
    t = max(t, 1ll);
    cout << getd(t) << endl;
    // cout << t << endl;
    while (q--)
    {
        int p, v;
        cin >> p >> v;
        if (s[p] > s[p + 1] && v <= s[p + 1])
        {
            chenge(1, n, p, 0, 1);
        }
        if (s[p] <= s[p + 1] && v > s[p + 1])
        {
            chenge(1, n, p, p, 1);
        }
        if (s[p - 1] > s[p] && s[p - 1] <= v && p >= 2)
        {
            chenge(1, n, p - 1, 0, 1);
        }
        if (s[p - 1] <= s[p] && s[p - 1] > v && p >= 2)
        {
            chenge(1, n, p - 1, p - 1, 1);
        }
        s[p] = v;
        int t = d[1];
        t = max(t, 1ll);
        // cout << " " << t << endl;
        cout << getd(t) << endl;
    }
}
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7736kb

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

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 279ms
memory: 16964kb

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'