QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#333273 | #7632. Balanced Arrays | wYYSZL | WA | 1ms | 9760kb | C++14 | 1.6kb | 2024-02-19 19:24:16 | 2024-02-19 19:24:17 |
Judging History
answer
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int n,m;
int hs1[2000006],hs2[2000006];
int a[2000006];
int pw1[2000006],pw2[2000006];
constexpr int base1=998244353,base2=1e9+7;
int tree[2000006];
int db[505];
int read(){
int x=0;char ch=getchar();
while(ch!=-1 and !db[ch])ch=getchar();
while(db[ch])x=x*62+db[ch],ch=getchar();
return x;
}
#define lowbit(x) (x&(-x))
void add(int x,int c){
for(;x<=n;x+=lowbit(x))tree[x]+=c;
return ;
}
int qu(int x){
int sum=0;
for(;x;x-=lowbit(x))sum+=tree[x];
return sum;
}
bool check(int mid,int k){
int hsh1=hs1[mid-2*k],hsh2=hs1[mid]-pw1[mid-2*k]*hs1[2*k];
// cout<<hsh1<<' '<<hsh2<<'\n';
hsh1+=hsh2;
int hsh3=hs1[mid-k]-pw1[mid-2*k]*hs1[k];
if(hsh1!=hsh3*2ull)return 0;
hsh1=hs2[mid-2*k],hsh2=hs2[mid]-pw2[mid-2*k]*hs2[2*k];
hsh1+=hsh2;
hsh3=hs2[mid-k]-pw2[mid-2*k]*hs2[k];
if(hsh1!=hsh3*2ull)return 0;
return 1;
}
signed main(){
// cin.tie(0)->sync_with_stdio(0);
//freopen("1.in","r",stdin);
cin>>n;
pw1[0]=pw2[0]=1;
for(int i=0;i<=9;++i)db[i+'0']=i;
for(int i=10;i<=10+25;++i)db[i-10+'a']=i;
for(int i=36;i<=36+25;++i)db[i-36+'A']=i;
for(int i=1;i<=n;++i){
a[i]=read();
hs1[i]=hs1[i-1]*base1+a[i];
hs2[i]=hs2[i-1]*base2+a[i];
pw1[i]=pw1[i-1]*base1;
pw2[i]=pw2[i-1]*base2;
}
for(int k=1;k<=(n-1)/2;++k){
int l=2*k+1,r=n;
while(l<r){
int mid=l+r>>1;
if(check(mid,k))l=mid+1;
else r=mid;
}
if(!check(l,k))--l;
cerr<<k<<' '<<l<<'\n';
if(l<2*k+1)continue;
add(2*k+1,1);add(l+1,-1);
}
for(int i=1;i<=n;++i)
cout<<(bool)(qu(i));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 9760kb
input:
2 2
output:
00
result:
wrong output format Expected integer, but "00" found