QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#296179 | #7877. Balanced Array | ucup-team870# | WA | 1ms | 9952kb | C++14 | 1.8kb | 2024-01-02 13:11:53 | 2024-01-02 13:11:54 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=2e6+6,bs=1e9+7;
const ll mod=(ll)1e18+3;
int a[N],mp[200],cf[N];
ll hs[N],pw[N],val[N];
ll mul(ll a,ll b){
ll tmp=(a*b- (ll)((long double)a/mod*b+0.5)*mod);
return tmp<0?tmp+mod:tmp;
}
ll cal(int l,int r){
--l;
ll val=hs[r]-mul(hs[l],pw[r-l]);
if(val<0)val+=mod; return val;
}
int main() {
IOS
rep(i,'0','9')mp[i]=i-'0';
rep(i,'a','z')mp[i]=i-'a'+10;
rep(i,'A','Z')mp[i]=i-'A'+36;
int n; cin>>n;
pw[0]=1; rep(i,1,n)pw[i]=mul(pw[i-1],bs);
rep(i,1,n){
string s;cin>>s;
for(auto c:s)a[i]=a[i]*62+mp[c];
}
// rep(i,1,n)cout<<a[i]<<" "; cout<<endl;
rep(i,1,n)hs[i]=(mul(hs[i-1],bs)+a[i])%mod;
rep(k,1,(n-1)/2){
rep(j,1,n/k)val[j]=cal((j-1)*k+1,j*k);
int r=3*k;
ll dif=(val[2]-val[1]+mod)%mod;
while(r<n){
int id=r/k;
if((val[id]-val[id-1]+dif+mod)%mod==0)r+=k;
else break;
}
int l=r-k+1; r=min(r,n);
int L=l,R=r;
while(L<=R){
int mid=(L+R)>>1;
// cout<<l<<" "<<mid<<"feaaega"<<endl;
if( 2*cal(l-k,mid-k)%mod == (cal(l,mid)+cal(l-2*k,mid-2*k))%mod)L=mid+1;
else R=mid-1;
// cout<<L<<" "<<R<<" "<<k<<endl;
}
int x=L-1;
// cout<<l<<" "<<r<<" ";
// cout<<k<<" "<<x<<endl;
++cf[2*k+1]; --cf[x+1];
}
int res=0;
rep(i,1,n){
res+=cf[i];
cout<<(res>0);
}
cout<<"\n";
}
/*
3
1 2 3
9
1C 3f 4S 3h 88 6x 4W d1 8c
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9676kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 1ms
memory: 9736kb
input:
9 1 2 3 2 5 4 3 8 5
output:
001010111
result:
ok single line: '001010111'
Test #3:
score: 0
Accepted
time: 0ms
memory: 9892kb
input:
9 1C 3f 4S 3h 88 6x 4W d1 8c
output:
001010111
result:
ok single line: '001010111'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 9952kb
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:
0000110011001000000000001000000000110000100000001
result:
wrong answer 1st lines differ - expected: '0000111111001000000000001000000000110000100000001', found: '0000110011001000000000001000000000110000100000001'