QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#287030#7967. 二进制lrherML 4ms65188kbC++144.2kb2023-12-19 12:20:142023-12-19 12:20:15

Judging History

你现在查看的是最新测评结果

  • [2023-12-19 12:20:15]
  • 评测
  • 测评结果:ML
  • 用时:4ms
  • 内存:65188kb
  • [2023-12-19 12:20:14]
  • 提交

answer

#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<bitset>
#include<vector>
#include<cstdio>
#include<random>
#include<complex>
#include<cstdlib>
#include<climits>
#include<iomanip>
#include<cstring>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
// #define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
// char buf[1<<21],*p1=buf,*p2=buf;
const long long _base=107374183;
int writetemp[30];
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;
    return x;
}
inline void write(int x)
{
    int t;
	int tot=(x==0);
    writetemp[1]=0;
	while(x) t=x/10,writetemp[++tot]=x-(t<<1)-(t<<3),x=t;
    for(int i=tot;i>=1;i--) putchar(writetemp[i]+'0');
    putchar('\n');
	return ;
}
const int sq=50001;
int n;
int nowl,nowr;
bool qvis[1000010];
char s[1000010];
int temp[1000010];
struct list
{
    int l,r;
}l[1000010];
int sz[1000010];
unordered_map<int,bool> vis[1000010];
priority_queue<int,vector<int>,greater<int> > q[50010];
struct BIT
{
    int c[1000010];
    void change(int x,int val)
    {
        while(x<=n) c[x]+=val,x+=x&(-x);
        return ;
    }
    int query(int x)
    {
        int ans=0;
        while(x) ans+=c[x],x-=x&(-x);
        return ans;
    }
}T;
void del(int x)
{
    if(l[x].l) l[l[x].l].r=l[x].r;
    if(l[x].r<=n) l[l[x].r].l=l[x].l;
    for(auto now:vis[x]) if(now.second==1&&nowl<=now.first&&now.first<=nowr) sz[now.first%sq]--;
    vis[x].clear();
    T.change(x,-1);
    return ;
}
void listdel(int x,int val)
{
    int len=__lg(val)+1;
    while(len--) del(x),x=l[x].r;
    return ;
}
void clear(int x)
{
    x=l[x].l;
    int len=20;
    while(len--) if(x)
    {
        for(auto now:vis[x]) if(now.second==1&&nowl<=now.first&&now.first<=nowr) sz[now.first%sq]--;
        vis[x].clear(),x=l[x].l;
    }
    return ;
}
void add(int x)
{
    x=l[x].l;
    int len=20;
    while(len--) if(x)
    {
        int nowpos=x,now=0;
        if(s[nowpos]=='1')
        {
            while(nowpos<=n)
            {
                now=(now<<1)+(s[nowpos]-'0');
                if(now>nowr) break;
                if(nowl<=now&&!qvis[now])
                {
                    q[now%sq].push(x);
                    vis[x][now]=1;
                    sz[now%sq]++;
                }
                nowpos=l[nowpos].r;
            }
        }
        x=l[x].l;
    }
    return ;
}
void init()
{
    int pos=0;
    for(int i=1;i<=n;i++) sz[i]=0;
    for(int i=1;i<=sq;i++) while(!q[i].empty()) q[i].pop();
    for(int i=1;i<=n;i++) if(T.query(i)!=T.query(i-1))
    {
        pos=i;
        break;
    }
    for(int i=pos;i<=n;i=l[i].r)
    {
        int now=0;
        vis[i].clear();
        if(s[i]=='0') continue;
        for(int j=i;j<=n;j=l[j].r)
        {
            now=(now<<1)+(s[j]-'0');
            if(now>nowr) break;
            if(nowl<=now)
            {
                // if(i==11) printf("initnow:%d\n",now);
                q[now%sq].push(i);
                vis[i][now]=1;
                sz[now%sq]++;
            }
        }
    }
    // printf("%d %d\n",nowl,nowr);
    // for(int i=pos;i<=n;i=l[i].r) printf("%c",s[i]);
    // printf("\n");
    return ;
}
int main()
{
    // freopen("s.out","r",stdin);
    // freopen("a.out","w",stdout);
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++) l[i].l=i-1,l[i].r=i+1;
    for(int i=1;i<=n;i++) T.change(i,1);
    nowr=-1;
    while(nowl<=n)
    {
        nowl=nowr+1,nowr=nowl+sq-1;
        init();
        for(int i=max(1,nowl);i<=min(nowr,n);i++)
        {
            while(!q[i%sq].empty()&&vis[q[i%sq].top()][i]==0) q[i%sq].pop();
            if(q[i%sq].empty()) printf("-1 0\n");
            else
            {
                int pos=q[i%sq].top();
                printf("%d %d\n",T.query(pos),sz[i%sq]);
                qvis[i]=1;
                clear(pos),listdel(pos,i),add(pos);
            }
        }
    }
    return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 65188kb

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
Memory Limit Exceeded

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: