QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#453829#8527. Power Divisionsucup-team3678WA 7ms34580kbC++142.7kb2024-06-24 12:34:382024-06-24 12:34:45

Judging History

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

  • [2024-06-24 12:34:45]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:34580kb
  • [2024-06-24 12:34:38]
  • 提交

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;
const __int128 MOD2 = (__int128)"8507059173023461586583651857942052727";

int a[N], f[N];
pair<int, int> mx[20][N];
long long pw[LIM], s[N];
__int128 pw2[LIM], s2[N];
unordered_map<long long, vector<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])) {
                    for (auto t : M[s[i] - pw[j] < 0 ? s[i] - pw[j] + MOD : s[i] - pw[j]]) {
                        --t;
                        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])) {
                    for (auto 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) && (pw2[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]].push_back(i - 1);
    }
    M[s[n]].push_back(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: 0
Wrong Answer
time: 7ms
memory: 34580kb

input:

5
2 0 0 1 1

output:

0

result:

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