QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#333274 | #7877. Balanced Array | wYYSZL | WA | 1ms | 5632kb | C++14 | 1.6kb | 2024-02-19 19:24:47 | 2024-02-19 19:24:47 |
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5632kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
9 1 2 3 2 5 4 3 8 5
output:
001010111
result:
ok single line: '001010111'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
9 1C 3f 4S 3h 88 6x 4W d1 8c
output:
001010111
result:
ok single line: '001010111'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
49 71FjQ 71FzG 71FjR 71FjG 71FjS 71F3G 71FjT 71ENG 71FjU 71ExG 71FzG 71Fko 71FjW 71FOM 71FPm 71FzG 71FPO 71FP9 71FzG 71Fkc 71FzG 7AXBr 71FPH 8nKLh 71Fk2 71FzG 71FkK 4AGIE 71Fk9 6EfCL 71FPN 71FjJ 71FPb 7H3TC 71Gks 71FzG 71FPI 71FzG 6Oayg 71FPc 71FPw 71FPN 71Fkm 71FPK 71FPK 6Az4J 71FPI 71FzG 71Fke
output:
0000111111001000000000001000000000110000100000001
result:
ok single line: '0000111111001000000000001000000000110000100000001'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3712kb
input:
48 4LZe2 4LZt4 4LZI6 4LZX8 4LZtY 4LZe2 4LZtX 4LZe2 4LYYd 4LYZ2 4LYZy 4LZe2 4LZtG 4LZtT 4LZe2 4LYtm 6g6ce 4LZe2 4LYYI 8MRDV 4LZu3 6tLzK 4WUft 7EU0p 5FVal 4LZe2 4LZe2 4LZu8 4LZe2 4LXtE 7KcGm 4LYXX 4LYYn 5v3aX 4LZtC 4LZu3 4LZe2 4LYYI 4LZtQ 4TSBp 4LYYB 4LZe2 4MatY 4LYYi 57PgU axOxK 6zQCA 4LZe2
output:
001100000000001100000000000000000000000000000000
result:
wrong answer 1st lines differ - expected: '001100000000001100000000000011100000000000001110', found: '001100000000001100000000000000000000000000000000'