QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#451536#8527. Power Divisionsucup-team3678WA 632ms120484kbC++142.5kb2024-06-23 16:30:432024-06-23 16:30:43

Judging History

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

  • [2024-06-23 16:30:43]
  • 评测
  • 测评结果:WA
  • 用时:632ms
  • 内存:120484kb
  • [2024-06-23 16:30:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 5, LIM = 1e6 + 20, P = 1e9 + 7;
const long long MOD = (1ll << 62) - 57, MOD2 = (1ll << 62) - 87;

int a[N], f[N];
pair<int, int> mx[20][N];
long long pw[LIM], s[N], pw2[LIM], s2[N];
unordered_map<long long, int> M;

void solve(int l, int r) {
    if (l > r) return;
    if (l == r) {
        ((f[r] += f[l - 1]) >= P) && (f[r] -= P);
        return;
    }
    int k = log2(r - l + 1), val, pos;
    tie(val, pos) = max(mx[k][l], mx[k][r - (1 << k) + 1]);
    solve(l, pos - 1);
    if (r - pos < pos - l) {
        for (int i = pos; i <= r; ++i) {
            for (int j = val; j < val + 20; ++j) {
                if (M.count(s[i] - pw[j] < 0 ? s[i] - pw[j] + MOD : s[i] - pw[j])) {
                    int t = M[s[i] - pw[j] < 0 ? s[i] - pw[j] + MOD : s[i] - pw[j]] + 1;
                    if (t >= l && t <= pos && (s2[i] - s2[t - 1] < 0 ? s2[i] - s2[t - 1] + MOD2 : s2[i] - s2[t - 1]) == pw2[j]) {
                        ((f[i] += f[t - 1]) >= P) && (f[i] -= P);
                    }
                }
            }
        }
    } else {
        for (int i = l; i <= pos; ++i) {
            for (int j = val; j < val + 20; ++j) {
                if (M.count(s[i - 1] + pw[j] >= MOD ? s[i - 1] + pw[j] - MOD : s[i - 1] + pw[j])) {
                    int t = M[s[i - 1] + pw[j] >= MOD ? s[i - 1] + pw[j] - MOD : s[i - 1] + pw[j]];
                    if (t >= pos && t <= r && (s2[t] - s2[i - 1] < 0 ? s2[t] - s2[i - 1] + MOD2 : s2[t] - s2[i - 1]) == pw2[j]) {
                        ((f[t] += f[i - 1]) >= P) && (f[t] -= P);
                    }
                }
            }
        }
    }
    solve(pos + 1, r);
}

signed main() {
    int n; scanf("%d", &n);
    for (int i = pw[0] = pw2[0] = 1; i < LIM; ++i) {
        ((pw[i] = pw[i - 1] << 1) >= MOD) && (pw[i] -= MOD);
        ((pw2[i] = pw2[i - 1] << 1) >= MOD2) && (pw[i] -= MOD2);
    }
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x), a[i] = x;
        mx[0][i] = make_pair(a[i], i);
        ((s[i] = s[i - 1] + pw[a[i]]) >= MOD) && (s[i] -= MOD);
        ((s2[i] = s2[i - 1] + pw2[a[i]]) >= MOD2) && (s2[i] -= MOD2);
        M[s[i - 1]] = i - 1;
    }
    M[s[n]] = n;
    for (int i = 1; (1 << i) <= n; ++i) {
        for (int j = 1; j + (1 << i) - 1 <= n; ++j) {
            mx[i][j] = max(mx[i - 1][j], mx[i - 1][j + (1 << (i - 1))]);
        }
    }
    f[0] = 1;
    solve(1, n);
    printf("%d\n", f[n]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 30344kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 6ms
memory: 22232kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 2ms
memory: 34444kb

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: 3ms
memory: 38804kb

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

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: 8ms
memory: 49284kb

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: 16ms
memory: 57820kb

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: 61ms
memory: 65188kb

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: 339ms
memory: 87008kb

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: 77ms
memory: 120484kb

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: 0
Accepted
time: 150ms
memory: 120428kb

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:

432100269

result:

ok 1 number(s): "432100269"

Test #17:

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

input:

299995
1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 1 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0 0 0 1 0 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 0 0...

output:

261818019

result:

ok 1 number(s): "261818019"

Test #18:

score: 0
Accepted
time: 404ms
memory: 86268kb

input:

299997
2 2 0 9 4 4 2 3 8 9 3 9 1 6 4 0 1 5 1 0 7 9 3 3 8 9 3 8 3 6 9 3 9 5 9 1 4 4 7 5 9 0 7 3 7 2 0 3 3 8 2 1 7 6 8 1 6 1 8 4 7 6 3 6 1 6 8 9 3 8 1 5 0 8 1 10 0 3 4 5 8 5 6 9 2 4 5 0 9 0 9 5 1 0 3 7 5 8 8 10 10 3 3 10 5 8 9 9 7 4 4 1 1 6 5 7 2 5 8 3 3 9 6 4 1 0 2 6 2 8 7 7 10 5 7 8 3 8 5 1 6 6 6 1 ...

output:

999738318

result:

ok 1 number(s): "999738318"

Test #19:

score: -100
Wrong Answer
time: 632ms
memory: 83496kb

input:

299999
97 34 33 30 15 73 31 69 60 63 79 87 78 13 49 58 23 38 91 28 70 70 14 98 56 59 81 66 29 21 10 51 94 32 41 98 16 48 67 62 55 5 17 81 30 91 39 93 73 74 46 74 41 99 19 10 0 16 72 95 84 40 97 17 76 10 42 50 66 97 4 30 71 74 46 5 75 87 55 82 38 94 14 82 49 10 23 21 19 99 52 100 71 29 64 73 54 88 2 ...

output:

0

result:

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