QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#448996#8527. Power Divisionsucup-team3282RE 1524ms252672kbC++142.6kb2024-06-20 15:50:512024-06-20 15:50:51

Judging History

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

  • [2024-06-20 15:50:51]
  • 评测
  • 测评结果:RE
  • 用时:1524ms
  • 内存:252672kb
  • [2024-06-20 15:50:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e18+3;
const int maxn=3e5+10;
const int maxv=1e6+10;
const int P=1e9+7;

ll pw[maxn+50];

int n;
int a[maxn];

struct interval{
    int l,r;
    friend bool operator<(const interval &x,const interval &y){
        if(x.r==y.r)
            return x.l<y.l;
        return x.r<y.r;
    }
};
set <interval> v;

map <ll,int> ml,mr;
bitset <maxv> t;
vector <int> p;
void solve(int l,int r){
    if(l==r){
        v.insert({l,r});
        return;
    }
    int mid=(l+r)>>1;

    ll s=0;
    for(int i=mid;i>=l;i--){
        s=(s+pw[a[i]])%mod;
        ml[s]=i;
    }
    s=0;
    for(int i=mid+1;i<=r;i++){
        s=(s+pw[a[i]])%mod;
        mr[s]=i;
    }
    s=0;
    int h=0;
    for(int i=mid;i>=l;i--){
        s=(s+pw[a[i]])%mod;
        if(t[a[i]]){
            int j;
            for(j=a[i];j>=0;j++)
                if(t[j])
                    t[j]=0;
                else
                    break;
            t[j]=1;
            p.push_back(j);
            h=max(h,j);
        }
        else{
            t[a[i]]=1;
            p.push_back(a[i]);
            h=max(h,a[i]);
        }
        ll st=(pw[h+1]-s+mod)%mod;
        if(mr.count(st)){
            v.insert({i,mr[st]});
        }
    }
    while(!p.empty()){
        t[p.back()]=0;
        p.pop_back();
    }
    s=0;
    h=0;
    for(int i=mid+1;i<=r;i++){
        s=(s+pw[a[i]])%mod;
        if(t[a[i]]){
            int j;
            for(j=a[i];j>=0;j++)
                if(t[j])
                    t[j]=0;
                else 
                    break;
            t[j]=1;
            p.push_back(j);
            h=max(h,j);
        }
        else{
            t[a[i]]=1;
            p.push_back(a[i]);
            h=max(h,a[i]);
        }
        ll st=(pw[h+1]-s+mod)%mod;
        if(ml.count(st)){
            v.insert({ml[st],i});
        }
    }
    while(!p.empty()){
        t[p.back()]=0;
        p.pop_back();
    }
    ml.clear();
    mr.clear();
    
    solve(l,mid);
    solve(mid+1,r);
}

ll f[maxn];
void dp(){
    f[0]=1;
    for(int i=1;i<=n;i++){
        while(!v.empty()&&v.begin()->r==i){
            int j=v.begin()->l;
            f[i]=(f[i]+f[j-1])%P;
            v.erase(v.begin());
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    pw[0]=1;
    for(int i=1;i<=maxn+30;i++)
        pw[i]=pw[i-1]*2%mod;

    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    
    solve(1,n);
    dp();
    cout<<f[n]<<endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8896kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

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: 2ms
memory: 8044kb

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: 2ms
memory: 8868kb

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: 5ms
memory: 9000kb

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: 20ms
memory: 9456kb

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: 119ms
memory: 16128kb

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: 757ms
memory: 47948kb

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: 1524ms
memory: 252672kb

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: