QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748525#9543. Good Partitions4eyebirdTL 928ms8632kbC++174.1kb2024-11-14 20:38:032024-11-14 20:38:04

Judging History

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

  • [2024-11-14 20:38:04]
  • 评测
  • 测评结果:TL
  • 用时:928ms
  • 内存:8632kb
  • [2024-11-14 20:38:03]
  • 提交

answer

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
constexpr int inf = 0x3f3f3f3f;

inline char gtc()
{
    static char BB[2000000], *S = BB, *T = BB;
    return S == T && (T = (S = BB) + fread(BB, 1, 2000000, stdin), S == T) ? EOF : *S++;
}

typedef long long ll;
inline int read()
{
    int x = 0, f = 1;
    char ch = gtc();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = gtc();
    }
    while (ch >= '0' && ch <= '9')
        x = (x << 3) + (x << 1) + (ch ^ 48), ch = gtc();
    return x * f;
}

inline void write(int x)
{
    if (x == 0)
    {
        putchar('0');
        return;
    }
    int len = 0;
    static char c[25];
    if (x < 0) x = -x, putchar('-');
    while (x) c[len++] = x % 10 + '0', x /= 10;
    while (len--) putchar(c[len]);
    putchar('\n');
}

typedef vector<int> vint;

int Ns;
int stm[524288];

inline void mat(int x, int y)
{
    static auto update = [&](int ps, int x, int L, int R, int p, auto self) -> void
    {
        if (L == R)
        {
            stm[p] += x;
            return;
        }
        int mid = (L + R) >> 1;
        if (ps <= mid)
            self(ps, x, L, mid, p << 1, self);
        else
            self(ps, x, mid + 1, R, p << 1 | 1, self);
        stm[p] = max(stm[p << 1], stm[p << 1 | 1]);
    };

    x--;
    int sp = sqrt(x);
    for (int i = 1; i <= sp; i++)
    {
        if (x % i == 0)
        {
            update(i, y, 1, Ns, 1, update);
            if (i != x / i)
                update(x / i, y, 1, Ns, 1, update);
        }
    }
}

inline int js(int x)
{
    int sp = sqrt(x), ret = 0;
    for (int i = 1; i <= sp; i++)
    {
        if (x % i == 0)
        {
            ret++;
            if (i != x / i)
                ret++;
        }
    }
    return ret;
}

int a[200010];
bool b[200010];

void solve()
{
    static auto query = [&](int L, int R, int p, auto self) -> int
    {
        if (L == R)
            return L;
        int mid = (L + R) >> 1;
        if (stm[p << 1 | 1] == stm[1])
            return self(mid + 1, R, p << 1 | 1, self);
        else
            return self(L, mid, p << 1, self);
    };

    int n = read(), q = read();

    if (n == 1)
    {
        int x = read();
        write(1);
        while (q--)
        {
            x = read();
            x = read();
            write(1);
        }
        return;
    }

    Ns = n + 1;
    memset(stm, 0, sizeof(stm));
    for (int i = 1; i <= n; i++)
    {
        b[i] = 0;
        a[i] = read();
    }
    for (int i = 2; i <= n; i++)
    {
        if (a[i] < a[i - 1])
        {
            b[i] = 1;
            mat(i, 1);
        }
    }
    if (stm[1] == 0)
        write(n);
    else
        write(js(query(1, Ns, 1, query)));
    while (q--)
    {
        int p = read(), x = read();
        if (b[p] && x >= a[p - 1])
        {
            b[p] = 0;
            mat(p, -1);
        }
        else if (!b[p] && x < a[p - 1])
        {
            b[p] = 1;
            mat(p, 1);
        }
        if (p + 1 <= n)
        {
            if (b[p + 1] && a[p + 1] >= x)
            {
                b[p + 1] = 0;
                mat(p + 1, -1);
            }
            else if (!b[p + 1] && a[p + 1] < x)
            {
                b[p + 1] = 1;
                mat(p + 1, 1);
            }
        }
        a[p] = x;
        if (stm[1] == 0)
            write(n);
        else
            write(js(query(1, Ns, 1, query)));
    }
}

void ts()
{
    int mx = -1, sum = 0;
    for (int i = 0; i <= 200000; i++)
    {
        sum += js(i);
        mx = max(mx, js(i));
    }
    cout << mx << ' ' << sum;
}

signed main()
{
#ifdef YGYYYGJ
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int _T_ = read();
    while (_T_--)
        solve();
    return 0;
}

詳細信息

Test #1:

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

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: 1ms
memory: 5536kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 928ms
memory: 8632kb

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: -100
Time Limit Exceeded

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: