QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771733#7877. Balanced Arrayeinekleine18RE 0ms0kbC++202.9kb2024-11-22 15:20:162024-11-22 15:20:16

Judging History

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

  • [2024-11-22 15:20:16]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-22 15:20:16]
  • 提交

answer

#include<bits/stdc++.h>
#include <cassert>
#include <cctype>
#include <vector>

#define int long long
constexpr int mod1=2147483647;
constexpr int mod2=2147483629;
constexpr int N=3e6+5;
struct Hash{
    int a,b;
    Hash operator+(const Hash&p) const {
        return {(a+p.a)%mod1,(b+p.b)%mod2};
    }
    Hash operator-(const Hash&p) const {
        return {(a-p.a+mod1)%mod1,(b-p.b+mod2)%mod2};
    }
    Hash operator*(const Hash&p) const {
        return {(a*p.a)%mod1,(b*p.b)%mod2};
    }
    bool operator==(const Hash&p) const {
        return a==p.a&&b==p.b;
    }
    bool operator<(const Hash&p) const {
        if(a!=p.a) return a<p.a;
        return b<p.b;
    }
}p[N];
Hash base{131,13331};
void slove(){
    p[0]={1,1};
    for(int i=1;i<N;++i){
        p[i]=p[i-1]*base;
    }
    auto get=[&](int l,int r,std::vector<Hash>&f)->Hash {
        return f[r]-f[l-1]*p[r-l+1];
    };
    auto hash=[&](std::vector<int>& s)->std::vector<Hash> {
        int sz=s.size();
        std::vector<Hash>f(sz+1);
        for(int i=1;i<=sz;++i){
            f[i]=f[i-1]*base+Hash({s[i-1]%mod1,s[i-1]%mod2});
        }
        return f;
    };
    int n;
    std::cin>>n;
    std::vector<int>a(n);
    for(int i=0;i<n;++i){
        std::string s;
        std::cin>>s;
        int val=0;
        for(auto &x:s){
            if(std::isupper(x)){
                val=val*62+x-'A'+36;
            }else if(std::islower(x)){
                val=val*62+x-'a'+10;
            }else{
                val=val*62+x-'0';
            }
        }
        a[i]=val;
    }
    std::vector<Hash> f=hash(a);
    std::vector<int>sum(n+1);
    auto ok=[&](int mid,int i)->bool {
        int l1=1,r1=mid-2*i;
        int l2=2*i+1,r2=mid;
        int l3=i+1,r3=mid-i;
        int flag=0;
        if(l1<=r1&&l2<=r2&&l3<=r3){
            if(get(l1,r1,f)+get(l2,r2,f)==get(l3,r3,f)+get(l3,r3,f)){
                flag=1;
            }
        }
        return flag;
    };
    // for(int i=0;i<n;++i){
    //     std::cout<<a[i]<<' ';
    // }
    // std::cout<<'\n';
    for(int i=1;i<=n/2;++i){
        int l=2*i+1,r=n;
        if(l>r) break;
        sum[l]+=1;
        while(l<r){
            int mid=l+r+1>>1;
            if(ok(mid,i)) l=mid;
            else r=mid-1;
        }
        // std::cout<<i<<' '<<l<<' '<<r<<'\n';
        if(ok(l,i)){
            assert(l+1<=n);
            sum[l+1]-=1;
        }else{
            sum[l]-=1;
        }
    }
    for(int i=1;i<=n;++i){
        sum[i]+=sum[i-1];
        if(sum[i]){
            std::cout<<1;
        }else{
            std::cout<<0;
        }
    }

}

signed main(){
#ifdef LOCAL
    std::freopen("in.txt","r",stdin);
    std::freopen("out.txt","w",stdout);
#endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _=1;
    // std::cin>>_;
    for(int i=0;i<_;++i){
        slove();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
1 2 3

output:


result: