QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#736331#9543. Good PartitionsRWeakestTL 0ms0kbC++203.0kb2024-11-12 10:08:532024-11-12 10:08:54

Judging History

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

  • [2024-11-12 10:08:54]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-12 10:08:53]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 2e5 + 100;

int ans[MAXN];

int cnt(int x)
{
    int num = 1;
    for (int i = 2; i * i <= x; ++i)
        if (!(x % i))
        {
            int temp = 0;
            while (!(x % i))
                x /= i, temp++;
            num *= (temp + 1);
        }
    return x == 1 ? num : num * 2;
}

void get_ans()
{
    for (int i = 1; i <= 200000; ++i)
        ans[i] = cnt(i);
    return;
}

int tree[MAXN], 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);
}

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

void build(int l, int r, int x)
{
    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);
}

int query(int l, int r, int nl, int nr, int p)
{
    if (l <= nl && nr <= r)
        return tree[p];
    int m = mid(nl, nr);
    int tot = 0;
    if (l <= m)
        tot = __gcd(tot, query(l, r, nl, m, ls(p)));
    if (r > m)
        tot = __gcd(tot, query(l, r, m + 1, nr, rs(p)));
    return tot;
}

void solve()
{
    int n, m;
    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;
    build(1, n, 1);
    cout << ans[query(1, n, 1, n, 1)] << "\n";
    while (m--)
    {
        int x, w;
        cin >> x >> w;
        if (x == n)
            continue;
        a[x] = w;
        if (!g[x])
        {
            if (a[x] > a[x + 1])
            {
                g[x] = x;
                modify(1, n, x, 1, x);
            }
        }
        else
        {
            if (a[x] <= a[x + 1])
            {
                g[x] = 0;
                modify(1, n, x, 1, 0);
            }
        }
        if (!g[x - 1])
        {
            if (a[x - 1] > a[x])
            {
                g[x - 1] = x - 1;
                modify(1, n, x - 1, 1, x - 1);
            }
        }
        else
        {
            if (a[x - 1] <= a[x])
            {
                g[x - 1] = 0;
                modify(1, n, x - 1, 1, 0);
            }
        }
        cout << ans[query(1, n, 1, n, 1)] << '\n';
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    get_ans();
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

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

output:


result: