QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#443305 | #8527. Power Divisions | ucup-team266# | WA | 7ms | 23152kb | C++17 | 1.5kb | 2024-06-15 15:06:13 | 2024-06-15 15:06:15 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef unsigned long long ull;
mt19937_64 rng(time(0));
const int N = 3e5 + 5, M = 1e6 + 30 + 5, Mod = 1e9 + 7;
int n = 0, m = 1000030, a[N] = {}, f[N] = {}, p = 0, q = 0, b[M] = {};
vector<int> v;
ull s[M] = {}, t[M] = {}, h = 0;
cc_hash_table<ull, int> g, g1, g2;
inline void calc(int x){
b[x] ^= 1, h ^= s[x], v.push_back(x);
if(!b[x]){
if(x == p) p ++;
calc(x + 1);
}
else{
if(p == -1 && q == -1) p = q = x;
else p = min(p, x), q = max(q, x);
}
}
inline void cdq(int l, int r){
if(r - l == 1) return;
int o = (l + r) / 2;
cdq(l, o);
g.clear(), g1.clear(), g2.clear();
for(int x : v) b[x] = 0;
v.clear(), h = 0, p = q = -1;
for(int i = o - 1 ; i >= l ; i --){
calc(a[i]);
g1[h] = (g1[h] + f[i]) % Mod, g2[h ^ t[p] ^ t[q]] = (g2[h ^ t[p] ^ t[q]] + f[i]) % Mod;
if(p == q) g[p] = (g[p] + f[i]) % Mod, f[o] = (f[o] + f[i]) % Mod;
}
for(int x : v) b[x] = 0;
v.clear(), h = 0, p = q = -1;
for(int i = o + 1 ; i < r ; i ++){
calc(a[i] - 1);
f[i] = (f[i] + g1[h ^ t[p] ^ t[q]]) % Mod, f[i] = (f[i] + g2[h]) % Mod;
if(p == q) f[i] = (f[i] + Mod - g[p]) % Mod;
}
cdq(o, r);
}
int main(){
for(int i = 0 ; i < m ; i ++){
s[i] = rng(), t[i] ^= s[i];
t[i + 1] = t[i];
}
scanf("%d", &n);
for(int i = 0 ; i < n ; i ++) scanf("%d", &a[n]);
f[0] = 1;
cdq(0, n + 1);
printf("%d", f[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 21848kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 3ms
memory: 23152kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 6ms
memory: 22060kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 5ms
memory: 22540kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: -100
Wrong Answer
time: 7ms
memory: 22404kb
input:
4 3 2 2 3
output:
2
result:
wrong answer 1st numbers differ - expected: '4', found: '2'