QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#444200#8527. Power Divisionsucup-team3926#TL 1439ms27400kbC++202.8kb2024-06-15 17:44:422024-06-15 17:44:42

Judging History

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

  • [2024-06-15 17:44:42]
  • 评测
  • 测评结果:TL
  • 用时:1439ms
  • 内存:27400kb
  • [2024-06-15 17:44:42]
  • 提交

answer

#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(a) (a).begin(), (a).end()

using namespace std;

#ifdef ONPC
mt19937 rnd(223);
mt19937_64 rnd64(223);
#else
mt19937 rnd(chrono::high_resolution_clock::now()
            .time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now()
            .time_since_epoch().count());
#endif

#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)

using ll = long long;
using ld = double;

const ll llinf = 1e18 + 100;

const int maxn = 1e6 + 100, inf = 1e9 + 100;

int n;

#define hash maksim
ll hash[maxn];
int a[maxn];

vector<int> e[maxn];

ll p[maxn];

int f[maxn];

ll S;
int big, sm;

void add(int v) {
    sm = min(sm, v);
    big = max(big, v);
    while (1) {
        S ^= hash[v];
        f[v] = !f[v];
        if (f[v]) {
            big = max(big, v);
            return;
        }
        if (sm == v)
            sm++;
        v++;
    }
}

unordered_map<ll, int> q;

void clear() {
    for (int i = sm; i <= big; i++)
        f[i] = 0;
    big = 0;
    sm = inf;
    S = 0;
}

void calc(int l, int r) {
    if (l == r)
        return;
    int m = (l + r) / 2;
    for (int i = m; i >= l; i--) {
        add(a[i]);
        // cerr << S << ' ' << i << '\n';
        assert(q.find(S) == q.end());
        q[S] = i;
    }
    clear();
    for (int i = m + 1; i <= r; i++) {
        add(a[i]);
        ll h = p[big + 1] ^ p[sm + 1] ^ S;
        if (q.find(h) != q.end())
            e[q[h]].push_back(i + 1);
    }
    q.clear();
    clear();
    for (int i = m + 1; i <= r; i++) {
        add(a[i]);
        // cerr << S << ' ' << i << '\n';
        assert(q.find(S) == q.end());
        q[S] = i;
    }
    clear();
    for (int i = m; i >= l; i--) {
        add(a[i]);
        ll h = p[big + 1] ^ p[sm + 1] ^ S;
        if (q.find(h) != q.end())
            e[i].push_back(q[h] + 1);
    }
    q.clear();
    clear();
    calc(l, m);
    calc(m + 1, r);
}

const int mod = 1e9 + 7;

void solve() {
    q.reserve(1e6);
    clear();
    for (int i = 0; i < maxn - 1; i++) {
        hash[i] = rnd64();
        p[i + 1] = p[i] ^ hash[i];
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        e[i].push_back(i + 1);
    }
    calc(0, n - 1);
    vector<int> dp(n + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        unordered_set<int> g{all(e[i])};
        for (int j : g) {
            // cerr << i << ' ' << j - 1 << '\n';
            dp[j] = (dp[j] + dp[i]) % mod;
        }
    }
    cout << dp[n] << '\n';
}

int main() {
#ifdef ONPC
    freopen("../a.in", "r", stdin);
    // freopen("../a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed;
    cout.precision(20);
    int ts = 1;
    // cin >> ts;
    while (ts--)
        solve();
    cerr << "\n\nConsumed " << TIME << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 27004kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 7ms
memory: 27168kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 10ms
memory: 27140kb

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 8ms
memory: 27008kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 8ms
memory: 26968kb

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 9ms
memory: 27232kb

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 14ms
memory: 27188kb

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 16ms
memory: 27188kb

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: 65ms
memory: 27008kb

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: 276ms
memory: 27164kb

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: 1439ms
memory: 27400kb

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: -100
Time Limit Exceeded

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:


result: