QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#444818#8527. Power Divisionsucup-team1198#WA 1091ms41128kbC++204.9kb2024-06-15 21:29:282024-06-15 21:29:29

Judging History

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

  • [2024-06-15 21:29:29]
  • 评测
  • 测评结果:WA
  • 用时:1091ms
  • 内存:41128kb
  • [2024-06-15 21:29:28]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

const int MOD = 1e9 + 7;

int add(int a, int b) {
  if (a + b < MOD)
    return a + b;
  return a + b - MOD;
}

int sub(int a, int b) {
  if (a >= b)
    return a - b;
  return a + MOD - b;
}

int mul(int a, int b) {
  return a * 1ll * b % MOD;
}

const int BASE = 447;
const int MAXN = (1 << 20) + 228;

int BASEPOW[MAXN];
int POWSUM[MAXN];

vector<int> from[MAXN];

int vals[MAXN];

int cur_hash = 0;
int cur_mn = -1;
int cur_mx = -1;
int inv_hash = 0;

vector<int> upds;

void add_bit(int i) {
  //cerr << "add_bit " << i << ' ';
  if (cur_mn == -1) {
    upds.emplace_back(i);
    vals[i] = 1;
    cur_mn = i;
    cur_mx = i;
    cur_hash = BASEPOW[i];
    inv_hash = BASEPOW[i];
  } else {
    inv_hash = sub(inv_hash, BASEPOW[cur_mn]);
    int l = i;
    while (vals[l] != 0) {
      upds.emplace_back(l);
      vals[l] ^= 1;
      cur_hash = sub(cur_hash, BASEPOW[l]);
      if (i != cur_mn)
        inv_hash = add(inv_hash, BASEPOW[l]);
      ++l;
    }
    vals[l] ^= 1;
    upds.emplace_back(l);
    cur_hash = add(cur_hash, BASEPOW[l]);
    if (l > cur_mx) {
      if (l == i) {
        inv_hash = add(inv_hash, sub(POWSUM[i], POWSUM[cur_mx + 1]));
      }
      cur_mx = l;
    } else {
      inv_hash = sub(inv_hash, BASEPOW[l]);
    }
    if (i == cur_mn) {
      cur_mn = l;
    } else if (i < cur_mn) {
      inv_hash = add(inv_hash, sub(POWSUM[cur_mn], POWSUM[i]));
      cur_mn = i;
    }
    inv_hash = add(inv_hash, BASEPOW[cur_mn]);
  }
  /*cerr << "\nhave: ";
  for (int j = 0; j < 15; ++j)
    cerr << ((cur_hash >> j) & 1);
  cerr << "\nneed: ";
  for (int j = 0; j < 15; ++j)
    cerr << ((inv_hash >> j) & 1);
  cerr << '\n';*/
}

void clear() {
  for (int i : upds)
    vals[i] = 0;
  upds.clear();
  cur_mn = -1;
  cur_mx = -1;
  cur_hash = 0;
  inv_hash = 0;

  //cerr << "cleared\n";
}

int A[MAXN];

void go_down(int left, int right) {
  if (left + 1 == right)
    return;
  int mid = (left + right) / 2;
  go_down(left, mid);
  go_down(mid, right);
  vector<pair<int, int>> hashes(right - left);
  clear();
  for (int i = mid - 1; i >= left; --i) {
    add_bit(A[i]);
    hashes[i - left] = make_pair(cur_hash, inv_hash);
  }
  clear();
  map<int, int> id;
  for (int i = mid; i < right; ++i) {
    add_bit(A[i]);
    hashes[i - left] = make_pair(cur_hash, inv_hash);
    id[cur_hash] = i;
  }
  for (int i = mid - 1; i >= left; --i) {
    int need = hashes[i - left].second;
    if (id.count(need)) {
      //cout << left << ' ' << mid << ' ' << right << ' ' << i << " - " << id[need] << ' ' << hashes[i - left].second << ',' << hashes[i - left].first << '\n';
      from[id[need] + 1].emplace_back(i);
    }
  }
  id.clear();
  for (int i = mid - 1; i >= left; --i) {
    id[hashes[i - left].first] = i;
  }
  for (int i = mid; i < right; ++i) {
    int need = hashes[i - left].second;
    if (id.count(need)) {
      //cout << left << ' ' << mid << ' ' << right << ' ' << id[need] << " - " << i << ' ' << hashes[i - left].second << ',' << hashes[i - left].first << '\n';
      from[i + 1].emplace_back(id[need]);
    }
  }
}

bool is_2pow(long long x) {
  while (x != 1) {
    if (x & 1)
      return false;
    x >>= 1;
  }
  return x == 1;
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  BASEPOW[0] = 1;
  for (int i = 1; i < MAXN; ++i)
    BASEPOW[i] = mul(BASEPOW[i - 1], BASE);
  POWSUM[0] = 0;
  for (int i = 1; i < MAXN; ++i)
    POWSUM[i] = add(POWSUM[i - 1], BASEPOW[i - 1]);

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> A[i];

  go_down(0, n);
  for (int i = 0; i < n; ++i) {
    from[i + 1].emplace_back(i);
  }

  vector<int> dp(n + 1);
  dp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    sort(from[i].begin(), from[i].end());
    from[i].resize(unique(from[i].begin(), from[i].end()) - from[i].begin());
    for (int j : from[i]) {
      //cout << j << ',' << i << '\n';
      dp[i] = add(dp[i], dp[j]);
    }
    /*vector<int> should;
    long long sum = 0;
    for (int j = i - 1; j >= 0; --j) {
      sum += 1ll << A[j];
      if (is_2pow(sum))
        should.emplace_back(j);
    }
    reverse(should.begin(), should.end());
    if (from[i] != should) {
      cerr << i << '\n';
      for (int x : from[i])
        cerr << x << ' ';
      cerr << '\n';
    for (int x : should)
        cerr << x << ' ';
      cerr << '\n';
      for (int j = should[0]; j < i; ++j)
        cerr << A[j] << ' ';
      cerr << '\n';
    }

    assert(should == from[i]);*/
  }
  cout << dp[n] << '\n';

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

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: 8ms
memory: 12616kb

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: 8ms
memory: 12948kb

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: 13ms
memory: 13084kb

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: 29ms
memory: 14836kb

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: 169ms
memory: 17036kb

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

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:

677203249

result:

wrong answer 1st numbers differ - expected: '842503795', found: '677203249'