QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#503019 | #8527. Power Divisions | ucup-team4435# | WA | 1ms | 5644kb | C++20 | 7.1kb | 2024-08-03 15:52:00 | 2024-08-03 15:52:01 |
Judging History
answer
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpl = vector<pl>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
int Bit(int mask, int b) { return (mask >> b) & 1; }
template<class T>
bool ckmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool ckmax(T &a, const T &b) {
if (b > a) {
a = b;
return true;
}
return false;
}
const int INFi = 2e9;
const ll INF = 2e18;
template<typename T>
int normalize(T value, int mod) {
if (value < -mod || value >= 2 * mod) value %= mod;
if (value < 0) value += mod;
if (value >= mod) value -= mod;
return value;
}
template<int mod>
struct static_modular_int {
using mint = static_modular_int<mod>;
int value;
static_modular_int() : value(0) {}
static_modular_int(const mint &x) : value(x.value) {}
template<typename T, typename U = std::enable_if_t<std::is_integral<T>::value>>
static_modular_int(T value) : value(normalize(value, mod)) {}
template<typename T>
mint power(T degree) const {
degree = normalize(degree, mod - 1);
mint prod = 1, a = *this;
for (; degree > 0; degree >>= 1, a *= a)
if (degree & 1)
prod *= a;
return prod;
}
mint inv() const {
return power(-1);
}
mint &operator=(const mint &x) {
value = x.value;
return *this;
}
mint &operator+=(const mint &x) {
value += x.value;
if (value >= mod) value -= mod;
return *this;
}
mint &operator-=(const mint &x) {
value -= x.value;
if (value < 0) value += mod;
return *this;
}
mint &operator*=(const mint &x) {
value = int64_t(value) * x.value % mod;
return *this;
}
mint &operator/=(const mint &x) {
return *this *= x.inv();
}
friend mint operator+(const mint &x, const mint &y) {
return mint(x) += y;
}
friend mint operator-(const mint &x, const mint &y) {
return mint(x) -= y;
}
friend mint operator*(const mint &x, const mint &y) {
return mint(x) *= y;
}
friend mint operator/(const mint &x, const mint &y) {
return mint(x) /= y;
}
mint &operator++() {
++value;
if (value == mod) value = 0;
return *this;
}
mint &operator--() {
--value;
if (value == -1) value = mod - 1;
return *this;
}
mint operator++(int) {
mint prev = *this;
value++;
if (value == mod) value = 0;
return prev;
}
mint operator--(int) {
mint prev = *this;
value--;
if (value == -1) value = mod - 1;
return prev;
}
mint operator-() const {
return mint(0) - *this;
}
bool operator==(const mint &x) const {
return value == x.value;
}
bool operator!=(const mint &x) const {
return value != x.value;
}
bool operator<(const mint &x) const {
return value < x.value;
}
template<typename T>
explicit operator T() {
return value;
}
friend std::istream &operator>>(std::istream &in, mint &x) {
std::string s;
in >> s;
x = 0;
for (const auto c: s)
x = x * 10 + (c - '0');
return in;
}
friend std::ostream &operator<<(std::ostream &out, const mint &x) {
return out << x.value;
}
static int primitive_root() {
if constexpr (mod == 1'000'000'007) return 5;
if constexpr (mod == 998'244'353) return 3;
if constexpr (mod == 786433) return 10;
static int root = -1;
if (root != -1)
return root;
std::vector<int> primes;
int value = mod - 1;
for (int i = 2; i * i <= value; i++)
if (value % i == 0) {
primes.push_back(i);
while (value % i == 0)
value /= i;
}
if (value != 1) primes.push_back(value);
for (int r = 2;; r++) {
bool ok = true;
for (auto p: primes) {
if ((mint(r).power((mod - 1) / p)).value == 1) {
ok = false;
break;
}
}
if (ok) return root = r;
}
}
};
constexpr int MOD = 1'000'000'007;
// constexpr int MOD = 998'244'353;
using mint = static_modular_int<MOD>;
const int N = 3e5 + 5;
int a[N];
mint dp[N];
struct MySet {
set<int> q;
void Add(int x) {
auto it = q.lower_bound(x);
while (it != q.end()) {
if (*it > x) break;
it = q.erase(it);
x++;
}
q.insert(x);
}
};
void rec(int l, int r) {
if (l == r) return;
if (l + 1 == r) {
dp[r] += dp[l];
return;
}
int mid = (l + r) / 2;
rec(l, mid);
{
// left >= right
MySet L, S;
int ri = mid;
for(int li = mid - 1; li >= l; --li) {
L.Add(a[li]);
S.Add(a[li]);
int high = *L.q.rbegin();
while (ri < r && *S.q.rbegin() < high + 1) {
S.Add(a[ri++]);
}
if (S.q.size() != 1 || *S.q.rbegin() != high + 1) {
continue;
}
dp[ri] += dp[li];
}
}
{
// left < right
MySet R, S;
int li = mid - 1;
S.Add(a[li]);
for(int ri = mid; ri < r; ++ri) {
R.Add(a[ri]);
S.Add(a[ri]);
int high = *R.q.rbegin();
while (li > l && *S.q.rbegin() < high + 1) {
S.Add(a[--li]);
}
if (S.q.size() != 1 || *S.q.rbegin() != high + 1 || R.q.size() == 1) {
continue;
}
dp[ri + 1] += dp[li];
}
}
rec(mid, r);
}
void solve() {
int n;
cin >> n;
rep(i, n) cin >> a[i];
dp[0] = 1;
rec(0, n);
cout << dp[n] << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(15) << fixed;
int t = 1;
// cin >> t;
rep(_, t) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5644kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4764kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 4700kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 4924kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 0ms
memory: 4784kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 4764kb
input:
5 3 4 4 2 4
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 4776kb
input:
7 3 4 3 5 6 3 4
output:
4
result:
wrong answer 1st numbers differ - expected: '6', found: '4'