QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515104 | #8527. Power Divisions | ngpin04 | WA | 13ms | 42300kb | C++14 | 4.5kb | 2024-08-11 15:13:59 | 2024-08-11 15:13:59 |
Judging History
answer
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define bit(n) (1LL << (n))
#define getbit(x, i) (((x) >> (i)) & 1)
#define pii pair<int, int>
#define ALL(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())
using namespace std;
const int M = 5e5 + 5;
const int mod = 1e9 + 7;
const int oo = 1e9;
const long long ooo = 1e18;
const double pi = acos(-1);
template<typename T1, typename T2> bool mini(T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned long long ull;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("file.inp", "r",stdin);
#endif
int n; cin >> n;
vector<int> a(n);
for (int &x : a) {
cin >> x;
x++;
}
vector<vector<int>> cand(n);
vector<int> dp(n + 1);
const int N = 2e6 + 5;
vector<int> cnt(N, 0);
vector<ull> hasher(N, 0), sum(N, 0);
for (int i = 1; i < N; i++) {
hasher[i] = rd();
sum[i] = hasher[i] + sum[i - 1];
}
auto getsum = [&](int l, int r) -> ull {
return sum[r] - sum[l - 1];
};
function<void(int, int)> solve = [&](int l, int r) -> void {
if (l == r) {
cand[r].push_back(r + 1);
return;
}
int mid = (l + r) >> 1;
int mx = -oo, mn = oo;
vector<int> vis;
set<pair<ull, int>> posl, posr;
ull cur = 0;
// cerr << l << " " << r << " " << mid << "\n";
for (int i = mid; i >= l; i--) {
maxi(mx, a[i]);
mini(mn, a[i]);
vis.push_back(a[i]);
cnt[a[i]]++;
cur += hasher[a[i]];
maxi(mx, a[i]);
int j = a[i];
while (cnt[j] > 1) {
if (j == mn) {
mn++;
maxi(mx, mn);
}
cnt[j] = 0;
cur -= 2 * hasher[j];
cnt[j + 1]++;
cur += hasher[j + 1];
vis.push_back(j + 1);
j++;
}
// cerr << "at " << i << ": " << cur << " " << getsum(mn, mx) - cur + hasher[mn] << " " << mn << " " << mx << "\n";
ull rev = getsum(mn, mx) - cur + hasher[mn];
posl.insert({cur, i});
posr.insert({rev, i});
}
for (int x : vis) {
cnt[x] = 0;
}
vis.clear();
mn = oo, mx = -oo;
cur = 0;
for (int i = mid + 1; i <= r; i++) {
maxi(mx, a[i]);
mini(mn, a[i]);
vis.push_back(a[i]);
cnt[a[i]]++;
cur += hasher[a[i]];
maxi(mx, a[i]);
int j = a[i];
while (cnt[j] > 1) {
if (j == mn) {
mn++;
maxi(mx, mn);
}
cnt[j] = 0;
cur -= 2 * hasher[j];
cnt[j + 1]++;
cur += hasher[j + 1];
vis.push_back(j + 1);
j++;
}
// cerr << "at " << i << ": " << cur << " " << getsum(mn, mx) - cur + hasher[mn] << " " << mn << " " << mx << "\n";
for (auto it = posr.lower_bound({cur, -oo}); it != posr.end() && it->fi == cur; it++) {
cand[it->se].push_back(i + 1);
}
ull rev = getsum(mn, mx) - cur + hasher[mn];
if (mn < mx) {
for (auto it = posl.lower_bound({rev, -oo}); it != posl.end() && it->fi == rev; it++) {
cand[it->se].push_back(i + 1);
}
}
}
for (int x : vis) {
cnt[x] = 0;
}
solve(l, mid);
solve(mid + 1, r);
};
solve(0, n - 1);
auto add = [&](int &a, int b) -> void {
a += b;
if (a >= mod)
a -= mod;
};
dp[0] = 1;
for (int i = 0; i < n; i++) {
for (int j : cand[i]) {
// cerr << i << " " << j - 1 << "\n";
add(dp[j], dp[i]);
}
}
cout << dp[n] << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 42236kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 4ms
memory: 42128kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 10ms
memory: 42188kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 4ms
memory: 42220kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 8ms
memory: 42204kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 6ms
memory: 42268kb
input:
5 3 4 4 2 4
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 6ms
memory: 42156kb
input:
7 3 4 3 5 6 3 4
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 8ms
memory: 42300kb
input:
10 8 6 5 6 7 8 6 8 9 9
output:
4
result:
ok 1 number(s): "4"
Test #9:
score: -100
Wrong Answer
time: 8ms
memory: 42188kb
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:
2177280
result:
wrong answer 1st numbers differ - expected: '11332014', found: '2177280'