QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#443136#8527. Power Divisionsucup-team180#WA 371ms32816kbC++172.4kb2024-06-15 14:31:292024-06-15 14:31:29

Judging History

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

  • [2024-06-15 14:31:29]
  • 评测
  • 测评结果:WA
  • 用时:371ms
  • 内存:32816kb
  • [2024-06-15 14:31:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000020;
const long long MOD_HASH = 522504475422956647;
const long long MOD = 1000000007;
vector<long long> POW;
struct number{
  vector<int> d;
  vector<int> idx;
  int h;
  long long s;
  number(): d(MAX), h(0), s(0){
  }
  void add(int i){
    d[i]++;
    idx.push_back(i);
    h = max(h, i);
    s += POW[i];
    s %= MOD;
    while (d[i] >= 2){
      d[i] = 0;
      d[i + 1]++;
      h = max(h, i + 1);
      idx.push_back(i + 1);
      i++;
    }
  }
  void reset(){
    for (int i : idx){
      d[i] = 0;
    }
    idx.clear();
    h = 0;
    s = 0;
  }
  long long solve(){
    return (POW[h + 1] - s + MOD_HASH) % MOD_HASH;
  }
};
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  POW.resize(MAX + 1);
  POW[0] = 1;
  for (int i = 0; i < MAX; i++){
    POW[i + 1] = POW[i] * 2 % MOD_HASH;
  }
  vector<long long> S(n + 1);
  S[0] = 0;
  for (int i = 0; i < n; i++){
    S[i + 1] = (S[i] + POW[a[i]]) % MOD_HASH;
  }
  vector<pair<long long, int>> P(n + 2);
  for (int i = 0; i <= n; i++){
    P[i] = make_pair(S[i], i);
  }
  P[n + 1] = make_pair(MOD_HASH, -1);
  sort(P.begin(), P.end());
  auto find = [&](long long x){
    int p = lower_bound(P.begin(), P.end(), make_pair(x, -1)) - P.begin();
    if (P[p].first == x){
      return P[p].second;
    } else {
      return -1;
    }
  };
  vector<long long> dp(n + 1, 0);
  dp[0] = 1;
  number SL, SR;
  auto dfs = [&](auto dfs, int L, int R) -> void {
    if (L >= R){
      return;
    }
    int M = (L + R) / 2;
    dfs(dfs, L, M - 1);
    SL.reset();
    for (int i = M - 1; i >= L; i--){
      SL.add(a[i]);
      long long x = (S[M] + SL.solve()) % MOD_HASH;
      int p = find(x);
      if (M + 1 <= p && p <= R){
        dp[p] += dp[i];
        dp[p] %= MOD;
      }
      if (SL.s == POW[SL.h]){
        dp[M] += dp[i];
        dp[M] %= MOD;
      }
    }
    SR.reset();
    for (int i = M + 1; i <= R; i++){
      SR.add(a[i - 1]);
      if (SR.s != POW[SR.h]){
        long long x = (S[M] - SR.solve() + MOD_HASH) % MOD_HASH;
        int p = find(x);
        if (L <= p && p <= M){
          dp[i] += dp[p];
          dp[i] %= MOD;
        }
      } else {
        dp[i] += dp[M];
        dp[i] %= MOD;
      }
    }
    dfs(dfs, M + 1, R);
  };
  dfs(dfs, 0, n);
  cout << dp[n] << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 18720kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 4ms
memory: 18976kb

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 4ms
memory: 18780kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 4ms
memory: 18776kb

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

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: 4ms
memory: 18740kb

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

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: 6ms
memory: 18944kb

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: 17ms
memory: 19628kb

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: 60ms
memory: 21688kb

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

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: 330ms
memory: 32788kb

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: -100
Wrong Answer
time: 371ms
memory: 32768kb

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:

0

result:

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