QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738296#9543. Good PartitionsRWeakestWA 112ms8156kbC++202.3kb2024-11-12 18:34:572024-11-12 18:35:01

Judging History

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

  • [2024-11-12 18:35:01]
  • 评测
  • 测评结果:WA
  • 用时:112ms
  • 内存:8156kb
  • [2024-11-12 18:34:57]
  • 提交

answer

#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 2e5 + 100;

int ans[MAXN];

void get_ans()
{
    for (int i = 1; i <= 2e5; ++i)
    {
        int sum = 0;
        for (int j = 1; j * j <= i; j++)
        {
            if (i % j == 0)
            {
                sum++;
                if (j * j != i)
                    sum++;
            }
        }
        ans[i] = sum;
    }
}

int tree[MAXN * 4], a[MAXN], g[MAXN], n, m;

int ls(int x)
{
    return x << 1;
}

int rs(int x)
{
    return (x << 1) | 1;
}

int mid(int l, int r)
{
    return l + ((r - l) >> 1);
}

void maintain(int x)
{
    tree[x] = __gcd(tree[ls(x)], tree[rs(x)]);
}

void build(int l, int r, int x)
{
    // cout << "l:" << l << " r:" << r << " x:" << x << "\n";
    if (l == r)
    {
        tree[x] = g[l];
        return;
    }
    int m = mid(l, r);
    build(l, m, ls(x)), build(m + 1, r, rs(x));
    maintain(x);
}

void modify(int l, int r, int x, int p, int num)
{
    if (l == r && l == x)
    {
        tree[p] = num;
        return;
    }
    if (mid(l, r) >= x)
        modify(l, mid(l, r), x, ls(p), num);
    if (x > mid(l, r))
        modify(mid(l, r) + 1, r, x, rs(p), num);
    maintain(p);
}

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

void solve()
{
    init();
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n - 1; ++i)
        if (a[i] > a[i + 1])
            g[i] = i;
        else
            g[i] = 0;
    g[n] = 0;
    build(1, n, 1);
    cout << ans[tree[1]] << "\n";
    while (m--)
    {
        int x, w;
        cin >> x >> w;
        a[x] = w;
        if (x != n)
        {
            if (a[x] > a[x + 1])
                modify(1, n, x, 1, x);
            else
                modify(1, n, x, 1, 0);
        }
        if (x != 1)
        {
            if (a[x - 1] > a[x])
                modify(1, n, x - 1, 1, x - 1);
            else
                modify(1, n, x - 1, 1, 0);
        }
        cout << ans[tree[1]] << '\n';
    }
}

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

    get_ans();
    ans[0] = n;
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 112ms
memory: 8156kb

input:

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

output:

1
2
3

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 112ms
memory: 6416kb

input:

1
1 1
2000000000
1 1999999999

output:

0
0

result:

wrong answer 1st lines differ - expected: '1', found: '0'