QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#714234#8527. Power Divisionsucup-team4992WA 11ms28480kbC++203.3kb2024-11-05 22:12:152024-11-05 22:12:16

Judging History

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

  • [2024-11-05 22:12:16]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:28480kb
  • [2024-11-05 22:12:15]
  • 提交

answer

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

const int MAXN = 300000+50;
const int MAX = 1e6+50;
const ll P = (1ll<<61)-1;
const ll mod = 1e9+7;
int n;
int a[MAXN], vl[MAX], vr[MAX];
multiset<int> s;
vector<int> vec[MAXN];
ll c[MAX], csum[MAX], dp[MAXN];
mt19937_64 rnd(time(0));

ll calc(int l, int r){
    if(l == 0) return csum[r];
    return (csum[r] - csum[l-1] + P) % P;
}

void solve(int l, int r){
    if(l == r){
        vec[r].push_back(l);
        return;
    }
    int mid = (l+r)/2;
    map<ll, int> ml, mr;
    ll hx = 0;
    for(int i = mid; i >= l; i--){
        vl[a[i]]++;
        hx = (hx + c[a[i]]) % P;
        s.insert(a[i]);
        for(int j = a[i]; ; j++){
            if(vl[j] >= 2){
                vl[j] -= 2;
                hx = (hx - 2*c[j]%P + P) % P;
                s.erase(s.find(j));
                s.erase(s.find(j));
                vl[j+1]++;
                hx = (hx + c[j+1]) % P;
                s.insert(j+1);
            }
            else{
                break;
            }
        }
        ml[hx] = i;
    }
    for(int p : s){
        vl[p] = 0;
    }
    s.clear();
    hx = 0;
    for(int i = mid+1; i <= r; i++){
        vr[a[i]]++;
        hx = (hx + c[a[i]]) % P;
        s.insert(a[i]);
        for(int j = a[i]; ; j++){
            if(vr[j] >= 2){
                vr[j] -= 2;
                hx = (hx - 2*c[j]%P + P) % P;
                s.erase(s.find(j));
                s.erase(s.find(j));
                vr[j+1]++;
                hx = (hx + c[j+1]) % P;
                s.insert(j+1);
            }
            else{
                break;
            }
        }
        int a = *s.begin();
        int b = *s.rbegin();
        ll h = (c[a] + calc(a, b) - hx + P) % P;
        if(ml.count(h)){
            vec[i].push_back(ml[h]);
        }
        mr[hx] = i;
    }
    for(int p : s){
        vr[p] = 0;
    }
    s.clear();
    hx = 0;
    for(int i = mid; i >= l; i--){
        vl[a[i]]++;
        hx = (hx + c[a[i]]) % P;
        s.insert(a[i]);
        for(int j = a[i]; ; j++){
            if(vl[j] >= 2){
                vl[j] -= 2;
                hx = (hx - 2*c[j]%P + P) % P;
                s.erase(s.find(j));
                s.erase(s.find(j));
                vl[j+1]++;
                hx = (hx + c[j+1]) % P;
                s.insert(j+1);
            }
            else{
                break;
            }
        }
        int a = *s.begin();
        int b = *s.rbegin();
        ll h = (c[a] + calc(a, b) - hx + P) % P;
        if(ml.count(h)){
            vec[mr[h]].push_back(i);
        }
    }
    for(int p : s){
        vl[p] = 0;
    }
    s.clear();
    solve(l, mid);
    solve(mid+1, r);
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 0; i <= 1000020; i++){
        c[i] = rnd() % P;
    }
    csum[0] = c[0];
    for(int i = 1; i <= 1000020; i++){
        csum[i] = (csum[i-1] + c[i]) % P;
    }
    solve(1, n);
    dp[0] = 1;
    for(int r = 1; r <= n; r++){
        for(int i = 0; i < vec[r].size(); i++){
            if(i > 0 && vec[r][i] == vec[r][i-1]) continue;
            int l = vec[r][i];
            dp[r] = (dp[r] + dp[l-1]) % mod;
        }
    }
    cout << dp[n] << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 24160kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 6ms
memory: 24160kb

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 11ms
memory: 24104kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: -100
Wrong Answer
time: 7ms
memory: 24388kb

input:

7
3 4 3 5 6 3 4

output:

5

result:

wrong answer 1st numbers differ - expected: '6', found: '5'