QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#451507#8527. Power DivisionsHKOI0#WA 3ms13744kbC++202.9kb2024-06-23 15:41:192024-06-23 15:41:20

Judging History

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

  • [2024-06-23 15:41:20]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13744kb
  • [2024-06-23 15:41:19]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define int long long
const int N = 3e5 + 11;
const int M = 1.1e6 + 11;
const int MOD = 1e9 + 7;
const int MOD2 = 888888877777777LL;
    
int dp[N], pw[M];

int mul(int a, int b){
    return (__int128_t) a * a % MOD2;
}

struct PartialSum{
    vector<int> h;
    unordered_map<int, int> mp;
    PartialSum(int n, vector<int> a) : h(n + 1){
        for (int i = 0; i < n; i++) {
            h[i + 1] = (h[i] + pw[a[i]]) % MOD2;
        }
        for (int i = 0; i <= n; i++) {
            mp[h[i]] = i;
        }
        for (auto x : h) cout << x << ' '; cout << endl;
    }
    int find(int x){
        if (x >= MOD2) x -= MOD2;
        if (x < 0) x += MOD2;
        if (mp.count(x)) { return mp[x]; }
        else return -1;
    }
};

vector<int> nxt[N];
void add_transition(int l, int r){
#ifdef LOCAL
    cout << "TRANSIT " << l << ' ' << r << endl;
#endif
    nxt[l].push_back(r);
}

void find_transit(PartialSum& ps, vector<int>& a, int l, int r, int i){
    // cout << "FIND" << ' ' << l << ' ' << r << ' ' << i << endl;
    for (int j = a[i]; j <= a[i] + 20; j++) {
        if (i - l <= r) {
            for (int x = l; x <= i; x++) {
                int idx = ps.find(ps.h[x] + pw[j]);
                if (idx == -1) continue;
                add_transition(x, idx);
            }
        } else {
            for (int x = i + 1; x <= r + 1; x++) {
                int idx = ps.find(ps.h[x] - pw[j]);
                if (idx == -1) continue;
                add_transition(idx, x);
            }
        }
    }
}

bool used[N];
void solve() {
    pw[0] = 1; for (int i = 1; i < M; i++) pw[i] = pw[i - 1] * 2 % MOD2;
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<pair<int, int>> V;
    for (int i = 0; i < n; i++) {
        V.push_back({a[i], i});
    }
    sort(all(V), [](auto x, auto y){
        return x.first > y.first || x.first == y.first && x.second > y.second;
    });

    set<int> S; S.insert(-1); S.insert(n);
    PartialSum PS(n, a);
    for (auto [v, i] : V) {
        auto ptr = S.lower_bound(i);
        int l = *prev(ptr) + 1, r = *ptr - 1;
        assert(l <= i && i <= r);
        find_transit(PS, a, l, r, i);
        S.insert(i);
    }

    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        for (auto x : nxt[i]) {
            if (used[x]) continue;
            used[x] = true; dp[x] = (dp[x] + dp[i]) % MOD;
        }
        for (auto x : nxt[i]) {
            used[x] = false;
        }
    }
    cout << dp[n] << '\n';
}

signed main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T = 1;
    // cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 13744kb

input:

5
2 0 0 1 1

output:

0 4 5 6 8 10 
6

result:

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