QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#451527#8527. Power Divisionsucup-team3678WA 5ms20312kbC++142.1kb2024-06-23 16:13:132024-06-23 16:13:13

Judging History

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

  • [2024-06-23 16:13:13]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:20312kb
  • [2024-06-23 16:13:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 5, LIM = 1e6 + 20, P = 1e9 + 7;
const long long MOD = 1e18 + 3;

int a[N], f[N];
pair<int, int> mx[20][N];
long long pw[LIM], s[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) {
                        ((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) {
                        ((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] = 1; i < LIM; ++i) {
        ((pw[i] = pw[i - 1] << 1) >= P) && (pw[i] -= P);
    }
    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]]) >= P) && (s[i] -= P);
        M[s[i - 1]] = i - 1;
    }
    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: 20236kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 5ms
memory: 16064kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 20312kb

input:

3
2 1 1

output:

2

result:

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