QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290936 | #7967. 二进制 | Famiglistmo | RE | 3ms | 11876kb | C++14 | 2.0kb | 2023-12-25 21:39:17 | 2023-12-25 21:39:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
int read(){
int s=0,w=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();};
while(isdigit(ch))s=s*10+(ch^48),ch=getchar();
return s*w;
}
int l[N],r[N],a[N],pos[N],cnt[N];
set<int> occ[N];
char s[N];
int n,k;
struct BIT{
int c[N];
int lowbit(int x){return -x&x;}
void add(int x,int v){for(;x<=n;x+=lowbit(x))c[x]+=v;}
int ask(int x){int r=0;for(;x;x-=lowbit(x))r+=c[x];return r;}
}B;
void upd(int num,int x,int op){
if(op==1)
occ[num].insert(x);
else
occ[num].erase(x);
int cur=num;
while(cur){
cnt[cur]=occ[cur].size();
pos[cur]=occ[cur].size()?*occ[cur].begin():n+1;
if((cur<<1)<=n)
pos[cur]=min(pos[cur],pos[cur<<1]),cnt[cur]+=cnt[cur<<1];
if((cur<<1|1)<=n)
pos[cur]=min(pos[cur],pos[cur<<1|1]),cnt[cur]+=cnt[cur<<1|1];
cur>>=1;
}
}
void alter(int x,int op){
if(a[x]){
int hsh=0;
for(int i=x;;i=r[i]){
hsh=hsh<<1|a[i];
if(r[i]>n||hsh*2+a[r[i]]>n)
{ upd(hsh,x,op);break; }
}
}
B.add(x,op);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>(s+1),k=__lg(n)+1;
for(int i=1;i<=n;++i)
a[i]=s[i]-'0',l[i]=i-1,r[i]=i+1,pos[i]=n+1;
l[n+1]=n;
for(int i=1;i<=n;++i)alter(i,1);
for(int i=1;i<=n;++i){
if(cnt[i]==0)
{ cout<<"-1 0\n"; continue; }
int x=pos[i],y=x;
cout<<B.ask(x)<<" "<<cnt[i]<<'\n';
for(int t=__lg(i)+1;t--;y=r[y])alter(y,-1);
for(int j=1,t=l[x];j<k&&t;++j,t=l[t])alter(t,-1);
r[l[x]]=y,l[y]=l[x];
for(int j=1,t=l[x];j<k&&t;++j,t=l[t])alter(t,1);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 11876kb
input:
20 01001101101101110010
output:
2 11 5 5 4 5 11 1 4 2 7 1 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0
result:
ok 20 lines
Test #2:
score: -100
Runtime Error
input:
1000000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...