QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#699758#8527. Power DivisionsgeorgeyucjrRE 1706ms35036kbC++175.3kb2024-11-02 10:37:562024-11-02 10:37:56

Judging History

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

  • [2024-11-02 10:37:56]
  • 评测
  • 测评结果:RE
  • 用时:1706ms
  • 内存:35036kb
  • [2024-11-02 10:37:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

// hashmap.cpp
#include <bits/stdc++.h>

#ifndef cpp17_inline_v
#if __cplusplus >= 201700LL
#define cpp17_inline_v inline
#else
#define cpp17_inline_v
#endif
#endif

// based on andyli

// unordered_map

template <typename T, const int _lg>
struct umap {
  static const uint64_t rng;
  cpp17_inline_v static constexpr int N = 1 << _lg;
  using key_type = uint64_t;
  key_type* Key = new key_type[N];
  T* val = new T[N];
  std::vector<int> ls;
  std::bitset<N> vis;
  inline static uint32_t gethash(key_type x) {
    return (key_type(x + rng) * 11995408973635179863ULL) >> (64 - _lg);
  }
  int get_idx(key_type val) const {
    int i = gethash(val);
    while (vis[i] && Key[i] != val) i = (i + 1) & (N - 1);
    return i;
  }
  T& operator[](key_type _val) {
    int i = get_idx(_val);
    if (!vis[i]) {
      vis[i] = true;
      Key[i] = _val;
      val[i] = {};
    }
    return val[i];
  }
  T getval(key_type _val, T not_exist) const {
    auto i = get_idx(_val);
    return vis[i] ? val[i] : not_exist;
  }
  bool count(key_type val) const {
    int i = get_idx(val);
    return vis[i];
  }
  void clearall() { vis.reset(); }
  ~umap() { delete[] Key, delete[] val; }
};

template <typename T, const int _lg>
const uint64_t umap<T, _lg>::rng =
    std::chrono::steady_clock::now().time_since_epoch().count();

template <typename T, const int _lg>
struct umap_safe {
  static const uint64_t rng;
  static constexpr int N = 1 << _lg;
  using key_type = uint64_t;
  key_type* Key = new key_type[N];
  T* val = new T[N];
  std::vector<int> ls;
  std::bitset<N> vis;
  std::vector<int> vc;
  static uint32_t gethash(key_type x) {
    return (key_type(x + rng) * 11995408973635179863ULL) >> (64 - _lg);
  }
  int get_idx(key_type val) const {
    int i = gethash(val);
    while (vis[i] && Key[i] != val) i = (i + 1) & (N - 1);
    return i;
  }
  T& operator[](key_type _val) {
    int i = get_idx(_val);
    if (!vis[i]) {
      vis[i] = true;
      Key[i] = _val;
      val[i] = {};
      vc.emplace_back(i);
    }
    return val[i];
  }
  T getval(key_type _val, T not_exist) const {
    auto i = get_idx(_val);
    return vis[i] ? val[i] : not_exist;
  }
  bool count(key_type val) const {
    int i = get_idx(val);
    return vis[i];
  }
  void clearall() {
    vis.reset();
    vc.clear();
  }
  void foorall(auto&& f) {
    for (auto x : vc) f(Key[x], val[x]);
  }
  ~umap_safe() { delete[] Key, delete[] val; }
};

template <typename T, const int _lg>
const uint64_t umap_safe<T, _lg>::rng =
    std::chrono::steady_clock::now().time_since_epoch().count();

#define rep(i, f, t, ...) for (int i = f, ##__VA_ARGS__; i <= t; ++i)
#define per(i, f, t, ...) for (int i = f, ##__VA_ARGS__; i >= t; --i)

using ll = long long;
using ull = unsigned long long;

template <typename T>
constexpr inline T inf = numeric_limits<T>::max() / 2;

constexpr int N = 3e5 + 105;
constexpr ll mod = 1e9 + 7;

int n, m, a[N];
ll dp[N];
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 m64rand(chrono::steady_clock::now().time_since_epoch().count());

namespace NH {
ull val[N], val_sum[N], cur = 0;
int cnt[N], mn, mx, Lim;
void init(int lim = m + 30) {
  Lim = lim;
  rep(i, 0, lim) val[i] = m64rand(); val_sum[0] = 0;
  partial_sum(val, val + lim + 1, val_sum + 1,
              [&](auto&& u, auto&& v) { return u ^ v; });
  // rep(i, 0, lim) cerr << val[i] << "\n";  
  cur = 0;
}
void clear() {
  assert(!cur);
  mn = Lim, mx = -1;
}
void add(int x) {
  // assert(x <= m + 3);
  for (; cnt[x]; ++x) {
    --cnt[x], cur ^= val[x];
    if (mn == x) ++mn;
  }
  ++cnt[x];
  cur ^= val[x];
  mx = max(mx, x), mn = min(mn, x);
}
void del(int x) {
  for (; !cnt[x]; ++x) ++cnt[x], cur ^= val[x];
  --cnt[x], cur ^= val[x];
}
ull qry() {
  assert(mn <= mx);
  return cur ^ val_sum[mn + 1] ^ val_sum[mx + 1];
}
}  // namespace NH

void add_mod(ll& x) {
  if (x >= mod) x -= mod;
}

void dvd(int l, int r) {  // [l, r)
  if (l + 1 == r) return dp[r] += dp[l], add_mod(dp[r]);
  int mid = (l + r) >> 1;
  dvd(l, mid);
  // less
  {
    umap_safe<ll, 20> M;
    NH::clear();
    per(i, mid - 1, l) NH::add(a[i]), M[NH::cur] += dp[i], add_mod(M[NH::cur]); // cerr << M[NH::cur] << " " << dp[i] << "\n";
    rep(i, l, mid - 1) NH::del(a[i]);
    NH::clear();
    rep(i, mid, r - 1) {
      NH::add(a[i]);
      if (NH::mn < NH::mx) {
        ll fd = M.getval(NH::qry(), -1);
        // cerr << "found " << fd << "\n";
        if (fd != -1) add_mod(dp[i + 1] += fd);
      }
    }
    per(i, r - 1, mid) NH::del(a[i]);
  }
  // equal or greater
  {
    umap_safe<ll, 20> M;
    NH::clear();
    per(i, mid - 1, l) NH::add(a[i]), add_mod(M[NH::qry()] += dp[i]); // cerr << M[NH::qry()] << " " << dp[i] << "\n";
    rep(i, l, mid - 1) NH::del(a[i]);
    NH::clear();
    rep(i, mid, r - 1) {
      NH::add(a[i]);
      ll fd = M.getval(NH::cur, -1);
      // cerr << "found " << fd << "\n";
      if (fd != -1) add_mod(dp[i + 1] += fd);
    }
    per(i, r - 1, mid) NH::del(a[i]);
  }
  dvd(mid, r);
}

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  rep(i, 0, n - 1) cin >> a[i];
  m = *max_element(a, a + n);
  dp[0] = 1;
  NH::init();
  dvd(0, n);
  cout << dp[n] << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 20776kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 8200kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 2ms
memory: 16124kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

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: 0ms
memory: 26332kb

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: 0ms
memory: 27980kb

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: 11ms
memory: 30824kb

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: 64ms
memory: 32112kb

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: 322ms
memory: 32640kb

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: 1706ms
memory: 35036kb

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: 1559ms
memory: 32468kb

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
Runtime Error

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:


result: