QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543133#8527. Power Divisionsucup-team4821#WA 1145ms52880kbC++203.3kb2024-09-01 14:13:412024-09-01 14:13:42

Judging History

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

  • [2024-09-01 14:13:42]
  • 评测
  • 测评结果:WA
  • 用时:1145ms
  • 内存:52880kb
  • [2024-09-01 14:13:41]
  • 提交

answer

#include <bits/stdc++.h>
template <unsigned long long MOD = 1000000007>
struct mint
{
    unsigned long long v;
    mint(unsigned long long v_ = 0) : v(v_) {}
    mint &operator+=(const mint &X) { return (v += X.v) >= MOD ? v -= MOD : v, *this; }
    mint &operator-=(const mint &X) { return (v += MOD - X.v) >= MOD ? v -= MOD : v, *this; }
    mint &operator*=(const mint &X) { return v = 1llu * v * X.v % MOD, *this; }
    mint &operator/=(const mint &X) { return *this *= X.inv(); }
    mint pow(long long B) const
    {
        mint res = 1, A = *this;
        while (B)
        {
            if (B & 1)
                res *= A;
            A *= A;
            B >>= 1;
        }
        return res;
    }
    friend mint operator+(const mint &A, const mint &B) { return mint(A) += B; }
    friend mint operator-(const mint &A, const mint &B) { return mint(A) -= B; }
    friend mint operator*(const mint &A, const mint &B) { return mint(A) *= B; }
    friend mint operator/(const mint &A, const mint &B) { return mint(A) /= B; }
    friend bool operator<(const mint &A, const mint &B) { return A.v < B.v; }
    friend bool operator==(const mint &A, const mint &B) { return A.v == B.v; }
    friend std::ostream &operator<<(std::ostream &A, const mint &B) { return A << B.v; }
};
mint<> dp[300005];
mint<1000'000'000'000'000'003> pw[1000105];
int n, a[300005];
void solve(int l, int r)
{
    static int b[1000100], tag[1000100], tim;
    if (r - l == 1)
    {
        dp[r] += dp[l];
        return;
    }
    int mid = (l + r) >> 1;
    solve(l, mid);
    std::map<mint<1000'000'000'000'000'003>, mint<>> map;
    mint<1000'000'000'000'000'003> cur;
    map.clear();
    ++tim;
    cur = 0;
    for (int i = mid; i-- != l;)
        map[cur += pw[a[i]]] += dp[i];
    cur = 0;
    for (int i = mid, max = 0; i != r; ++i)
    {
        if (tag[a[i]] != tim)
            tag[a[i]] = tim, b[a[i]] = 0;
        ++b[a[i]];
        cur += pw[a[i]];
        max = std::max(max, a[i]);
        for (int j = a[i]; b[j] >= 2; ++j)
        {
            if (tag[j + 1] != tim)
                tag[j + 1] = tim, b[j + 1] = 0;
            b[j + 1] += b[j] >> 1;
            b[j] &= 1;
            max = std::max(max, j + 1);
        }
        dp[i + 1] += map[pw[max + 1] - cur];
    }
    map.clear();
    ++tim;
    cur = 0;
    for (int i = mid, max = 0; i-- != l;)
    {
        if (tag[a[i]] != tim)
            tag[a[i]] = tim, b[a[i]] = 0;
        ++b[a[i]];
        cur += pw[a[i]];
        max = std::max(max, a[i]);
        for (int j = a[i]; b[j] >= 2; ++j)
        {
            if (tag[j + 1] != tim)
                tag[j + 1] = tim, b[j + 1] = 0;
            b[j + 1] += b[j] >> 1;
            b[j] &= 1;
            max = std::max(max, j + 1);
        }
        if (cur == pw[max])
            continue;
        map[pw[max + 1] - cur] += dp[i];
    }
    cur = 0;
    for (int i = mid; i != r; ++i)
        dp[i + 1] += map[cur += pw[a[i]]];
    solve(mid, r);
}
signed main()
{
    std::ios::sync_with_stdio(false);
    pw[0] = 1;
    for (int i = 1; i <= 1000000; ++i)
        pw[i] = pw[i - 1] + pw[i - 1];
    std::cin >> n;
    for (int i = 0; i != n; ++i)
        std::cin >> a[i];
    dp[0] = 1;
    solve(0, n);
    std::cout << dp[n] << std::endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 17956kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 15856kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 15972kb

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 4ms
memory: 16120kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 4ms
memory: 16268kb

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 0ms
memory: 16224kb

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 0ms
memory: 17968kb

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 3ms
memory: 16180kb

input:

10
8 6 5 6 7 8 6 8 9 9

output:

4

result:

ok 1 number(s): "4"

Test #9:

score: 0
Accepted
time: 0ms
memory: 15960kb

input:

96
5 1 0 2 5 5 2 4 2 4 4 2 3 4 0 2 1 4 3 1 2 0 2 2 3 2 4 5 3 5 2 0 2 2 5 3 0 4 5 3 5 4 4 3 1 2 0 5 4 5 0 2 3 2 4 0 0 4 2 0 2 5 3 3 1 5 5 1 1 1 0 5 0 3 0 2 1 1 0 5 0 3 3 4 4 5 3 0 2 2 0 5 4 5 0 5

output:

11332014

result:

ok 1 number(s): "11332014"

Test #10:

score: 0
Accepted
time: 0ms
memory: 16232kb

input:

480
2 0 4 4 1 0 0 3 1 1 4 2 5 5 4 2 1 2 4 4 1 3 4 3 0 5 2 0 2 5 1 0 5 0 0 5 5 0 2 5 2 2 3 1 4 3 5 4 5 2 4 4 4 4 1 4 0 3 4 3 4 1 0 4 3 4 5 4 3 5 0 2 2 0 1 5 4 4 2 0 3 3 3 4 3 0 5 5 3 1 5 1 0 1 0 4 3 0 5 1 4 1 4 3 0 1 3 5 0 3 3 1 0 4 1 1 2 0 1 2 0 3 5 2 0 5 5 5 5 3 5 1 0 2 5 2 2 0 2 0 2 3 5 1 2 1 5 4 ...

output:

506782981

result:

ok 1 number(s): "506782981"

Test #11:

score: 0
Accepted
time: 3ms
memory: 18188kb

input:

2400
0 2 2 0 5 4 3 2 3 2 5 4 5 4 4 5 2 2 4 2 2 0 1 0 5 0 4 4 0 0 5 0 4 0 1 3 4 5 0 3 1 0 4 0 2 5 0 3 3 3 3 1 0 5 5 3 1 3 5 2 4 0 5 0 4 5 4 2 2 1 5 2 2 4 1 0 5 1 5 0 1 2 0 0 3 5 4 0 0 1 1 1 4 2 0 5 1 3 3 5 0 4 4 1 5 5 3 4 4 4 0 2 4 0 5 1 3 1 5 0 5 5 1 3 0 3 1 2 0 1 1 3 5 2 3 4 0 3 0 5 4 0 4 3 5 0 5 2...

output:

586570528

result:

ok 1 number(s): "586570528"

Test #12:

score: 0
Accepted
time: 23ms
memory: 18260kb

input:

12000
2 2 1 2 0 2 5 3 2 0 1 3 2 5 4 0 0 5 3 2 0 2 3 4 3 2 1 4 3 0 3 5 4 1 0 2 4 1 3 2 3 5 0 3 0 0 4 0 4 5 1 0 4 1 1 1 5 4 3 0 3 5 4 5 2 5 0 1 2 3 5 5 2 5 4 2 0 4 4 3 0 0 2 5 0 3 4 2 5 4 2 1 4 5 1 1 2 3 0 3 3 3 3 4 0 5 3 4 0 3 0 2 0 0 2 0 3 4 2 2 0 1 0 5 3 0 2 0 2 2 1 0 5 3 5 4 5 5 0 4 0 4 1 4 4 3 2 ...

output:

201653965

result:

ok 1 number(s): "201653965"

Test #13:

score: 0
Accepted
time: 153ms
memory: 23628kb

input:

60000
2 5 0 3 2 3 5 3 5 5 4 1 1 5 3 0 1 1 2 5 5 5 0 3 2 0 3 2 3 3 0 0 1 4 3 1 4 2 3 3 0 5 1 0 1 1 5 5 4 0 5 4 1 3 1 3 5 3 2 4 4 4 5 4 3 2 3 2 4 5 2 0 4 5 1 2 0 4 0 5 1 3 4 1 2 4 1 1 3 3 0 1 1 3 0 0 2 3 3 2 1 4 1 2 4 3 3 5 2 5 3 4 3 0 2 1 1 1 5 1 2 4 2 3 1 2 1 0 2 0 1 1 5 5 3 4 2 5 2 4 5 3 0 5 1 4 2 ...

output:

592751350

result:

ok 1 number(s): "592751350"

Test #14:

score: 0
Accepted
time: 962ms
memory: 52880kb

input:

300000
0 5 1 5 5 4 5 3 0 5 0 5 1 4 1 2 2 2 3 0 1 5 4 0 3 1 4 5 2 1 0 3 2 1 2 5 0 2 4 5 0 1 2 1 1 0 0 5 3 0 0 3 4 5 0 2 1 1 1 2 5 1 4 3 1 0 2 0 0 4 3 3 2 5 3 3 1 5 2 0 2 4 3 1 0 3 4 1 3 3 1 0 0 1 1 1 3 1 2 3 5 3 3 2 0 3 0 0 5 5 0 0 0 0 1 4 3 3 4 3 4 5 3 3 5 1 1 4 2 2 1 3 2 1 1 0 0 5 5 0 0 3 2 4 5 5 2...

output:

842503795

result:

ok 1 number(s): "842503795"

Test #15:

score: 0
Accepted
time: 485ms
memory: 35780kb

input:

300000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

432100269

result:

ok 1 number(s): "432100269"

Test #16:

score: -100
Wrong Answer
time: 1145ms
memory: 52508kb

input:

300000
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 10000...

output:

1

result:

wrong answer 1st numbers differ - expected: '432100269', found: '1'