QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290219 | #7967. 二进制 | daydream# | TL | 4124ms | 175852kb | C++20 | 1.9kb | 2023-12-24 16:16:29 | 2023-12-24 16:16:29 |
Judging History
answer
#include<bits/stdc++.h>
#define db double
#define LL long long
#define pb push_back
#define eb emplace_back
#define pli pair<LL,int>
#define pii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
using namespace std;
const int dx[]={0,1,0,-1,1,1,-1,-1},
dy[]={1,0,-1,0,1,-1,1,-1};
struct BIT
{
int n;
vector<int> tr;
BIT(int N)
{
tr.resize((n=N)+10);
}
void upd(int i) {for(;i<=n;i+=(i&-i)) tr[i]++;}
int qry(int i) {int res=0; for(;i;i-=(i&-i)) res+=tr[i]; return res;}
};
int n;
void solve()
{
cin>>n;
string s;cin>>s;s=" "+s;
vector<int> a(n+10),f(n+10),ex(n+10,1),nxt(n+10),pre(n+10),cnt(n*2+10);
vector<set<int>> pos(n*2+10);
nxt[n+1]=n+1;nxt[0]=1;pre[n+1]=n;
for(int i=1;i<=n;++i) a[i]=s[i]-'0',nxt[i]=i+1,pre[i]=i-1;
BIT T(n);
for(int k=1,x=1;x<=n;++k,x<<=1)
{
int S=(1<<k)-1;
{
int p=nxt[0],ps=p,x=0;
for(int j=1;j<k;++j,ps=nxt[ps]) x=x<<1|a[ps];
for(;ps<=n;p=nxt[p],ps=nxt[ps])
{
x=((x<<1)&S)|a[ps];
f[p]=x;
cnt[f[p]]++;pos[f[p]].insert(p);
}
}
// cout<<'\n';
for(int i=x;i<=n&&i<(x<<1);++i)
{
// cout<<cnt[7]<<'\n';
if(!cnt[i])
{
cout<<"-1 0\n";
continue;
}
int P=*pos[i].begin(),p=P;
cout<<p-T.qry(p)<<' '<<cnt[i]<<'\n';
for(int j=1;j<=k;++j,p=nxt[p])
{
ex[p]=0;
T.upd(p);
cnt[f[p]]--;
pos[f[p]].erase(p);
}
nxt[pre[P]]=p;pre[p]=pre[P];
p=P;
for(int j=1;j<k;++j) p=pre[p];
if(!p) p=nxt[p];
int x=0,ps=p;
for(int j=1;j<k;++j,ps=nxt[ps]) x=x<<1|a[ps];
for(int j=1;j<k;++j,p=nxt[p],ps=nxt[ps])
{
cnt[f[p]]--;pos[f[p]].erase(p);
if(ps<=n)
{
x=((x<<1)&S)|a[ps];
f[p]=x;
cnt[f[p]]++;pos[f[p]].insert(p);
}
}
pos[i].clear();
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int TT=1;
// cin>>TT;
for(;TT;--TT) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3452kb
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: 0
Accepted
time: 4124ms
memory: 175852kb
input:
1000000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1 1000000 -1 0 1 999998 -1 0 -1 0 -1 0 1 999995 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 1 999991 -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 -1 0 1 999986 -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 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0...
result:
ok 1000000 lines
Test #3:
score: -100
Time Limit Exceeded
input:
1000000 1111111101011101110011011111111111111110110011110111011100111001011011011110101110111111111111111111111111011111101111110110111111111110111010111111100110011101101110011111111101111110111111111110111111111111011011110110111101101101110101100111111111001010111111111111010111011111111011110111...
output:
1 800681 7 159535 1 641144 13 31730 5 127804 5 127761 1 513379 542 6405 25 25324 54 25337 5 102464 30 25561 17 102196 17 102484 1 410890 2647 1324 618 5080 20 5103 99 20219 304 4894 89 20442 21 20308 15 82150 810 5135 82 20422 158 20309 20 81880 83 20567 39 81909 40 82119 1 328769 4222 267 2829 1056...