QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#621841#8546. Min or Max 2ucup-team3651TL 3816ms85592kbC++203.9kb2024-10-08 17:27:062024-10-08 17:27:06

Judging History

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

  • [2024-10-08 17:27:06]
  • 评测
  • 测评结果:TL
  • 用时:3816ms
  • 内存:85592kb
  • [2024-10-08 17:27:06]
  • 提交

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array

#define N 500005

using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(int x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}

struct info{
    int f[9];
    info(){memset(f,0,sizeof(f));}
}c[9];
int tmpB[9];
info merge(info x,info y){
    info z;
    for(int i=0;i<9;i++)tmpB[i]=0;
    for(int i=0;i<9;i++){
        tmpB[0]|=((y.f[i]&(1<<0))?(1<<i):0);
        tmpB[1]|=((y.f[i]&(1<<1))?(1<<i):0);
        tmpB[2]|=((y.f[i]&(1<<2))?(1<<i):0);
        tmpB[3]|=((y.f[i]&(1<<3))?(1<<i):0);
        tmpB[4]|=((y.f[i]&(1<<4))?(1<<i):0);
        tmpB[5]|=((y.f[i]&(1<<5))?(1<<i):0);
        tmpB[6]|=((y.f[i]&(1<<6))?(1<<i):0);
        tmpB[7]|=((y.f[i]&(1<<7))?(1<<i):0);
        tmpB[8]|=((y.f[i]&(1<<8))?(1<<i):0);
    }
    for(int i=0;i<9;i++){
        for(int j=0;j<9;j++){
            z.f[i]|=(1<<j)*((x.f[i]&tmpB[j])!=0);
        }
    }
    return z;
}
int id(int x,int y){
    return x+3*y;
}
void init(){
    for(int x=0;x<3;x++){
        for(int y=0;y<3;y++){
            for(int i=0;i<3;i++){
                for(int j=0;j<3;j++){
                    int u=min(i,x),v=min(y,j);
                    c[id(x,y)].f[id(i,j)]|=(1<<(id(u,v)));
                    u=max(i,x);v=max(y,j);
                    c[id(x,y)].f[id(i,j)]|=(1<<(id(u,v)));
                }
            }
        }
    }
}

int X=1,Y=1,n;
int res[N];
int cp(int x,int y){
    return (x==y?1:(x<y?0:2));
}
int a[N],b[N],A[N],B[N];

struct seg{
    int ls[N<<2],rs[N<<2],tot;info v[N<<2];
    void build(int &x,int l=2,int r=n){
        x=++tot;if(l==r)return v[x]=c[id(cp(a[l],X),cp(b[l],Y))],void();int mid=(l+r)>>1;
        build(ls[x],l,mid);build(rs[x],mid+1,r);v[x]=merge(v[ls[x]],v[rs[x]]);
    }
    void fresh(int x,int p,int l=2,int r=n){
        if(l==r)return v[x]=c[id(cp(a[l],X),cp(b[l],Y))],void();int mid=(l+r)>>1;
        (p<=mid)?fresh(ls[x],p,l,mid):fresh(rs[x],p,mid+1,r);v[x]=merge(v[ls[x]],v[rs[x]]);
    }
}T;

bool chk(){
    int now=id(cp(a[1],X),cp(b[1],Y));
    if(T.v[1].f[now]&(1<<(id(1,1))))return true;
    return false;
}

void solve(){
    n=read();T.tot=0;X=1;Y=1;
    for(int i=0;i<=n;i++)res[i]=0;
    for(int i=1;i<=n;i++)a[i]=read(),A[a[i]]=i;
    for(int i=1;i<=n;i++)b[i]=read(),B[b[i]]=i;
    int rt;T.build(rt);
    if(chk())res[abs(X-Y)]++;
    while(1){
        auto update=[&](int optx,int opty){
            if(optx){
                T.fresh(rt,A[X]);
                if(optx==1)T.fresh(rt,A[X-1]);
                else T.fresh(rt,A[X+1]);
            }
            if(opty){
                T.fresh(rt,B[Y]);
                if(opty==1)T.fresh(rt,B[Y-1]);
                else T.fresh(rt,B[Y+1]);
            }
        };
        if(X+1<=n){
            X++;update(1,0);
            if(chk()){res[abs(X-Y)]++;continue;}
            X--;update(2,0);
        }
        if(Y+1<=n){
            Y++;update(0,1);
            if(chk()){res[abs(X-Y)]++;continue;}
            Y--;update(0,2);
        }
        if(X+1<=n && Y+1<=n){
            X++;Y++;update(1,1);
            if(chk()){res[abs(X-Y)]++;continue;}
            break;
        }
        break;
    }
    for(int i=0;i<n;i++)write(res[i]),putchar(' ');
    putchar('\n');
}

int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    #endif
    init();
    int T=read();while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 74216kb

input:

4
2
1 2
2 1
5
2 4 1 5 3
2 4 1 5 3
5
1 2 3 4 5
5 4 3 2 1
8
5 8 3 4 2 7 1 6
4 6 3 8 5 1 2 7

output:

2 0 
5 0 0 0 0 
2 2 2 2 0 
5 5 2 2 1 0 0 0 

result:

ok 20 numbers

Test #2:

score: 0
Accepted
time: 1231ms
memory: 74716kb

input:

66664
7
4 2 6 5 7 1 3
6 5 3 1 4 7 2
10
6 8 10 7 5 1 4 3 9 2
5 10 3 8 6 7 2 9 1 4
9
3 2 4 8 7 6 9 1 5
8 1 2 9 6 7 4 3 5
10
4 3 9 6 7 2 10 1 8 5
3 5 4 1 2 7 10 9 6 8
5
3 4 1 2 5
5 1 3 2 4
5
2 4 3 5 1
2 3 1 4 5
6
2 6 1 3 4 5
6 4 5 1 3 2
10
10 1 2 7 5 8 4 3 9 6
9 4 2 3 6 1 7 8 5 10
5
1 2 4 5 3
4 1 2 5 3...

output:

4 4 2 2 1 0 0 
5 6 3 2 2 1 0 0 0 0 
5 6 3 2 1 0 0 0 0 
4 4 4 3 2 1 0 0 0 0 
5 3 0 0 0 
2 2 2 2 0 
3 3 3 1 0 0 
5 7 4 2 1 0 0 0 0 0 
5 2 0 0 0 
6 3 0 0 0 0 
3 3 2 0 0 
5 4 2 1 0 0 0 
3 2 3 1 0 0 
4 6 3 0 0 0 0 
3 4 3 2 1 0 0 
3 2 2 2 2 2 2 1 0 
4 5 3 1 0 0 0 
3 4 3 2 3 3 1 0 0 0 
8 5 0 0 0 0 0 0 
7 8...

result:

ok 499999 numbers

Test #3:

score: 0
Accepted
time: 2588ms
memory: 85588kb

input:

6690
72
31 50 47 60 24 33 72 49 5 26 17 65 40 64 8 2 19 51 30 58 71 16 66 56 9 48 21 61 44 59 22 11 15 28 68 29 1 27 37 41 23 6 20 62 43 34 18 4 70 54 13 12 36 35 25 67 45 38 69 53 42 63 55 3 14 7 57 32 52 39 10 46
31 9 7 56 32 64 39 33 62 24 49 54 18 53 43 40 4 28 37 2 61 47 10 26 23 16 22 30 11 60...

output:

7 11 7 5 6 6 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 2 2 2 3 4 4 4 4 4 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
3 4 6 6 4 4 3 2 2 2 2 2 2 2 2 2 3 4 4 4 4 4 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
4 6 6 7 8 7 6 7 8 8 7 5 4 4 3 2 2 2...

result:

ok 499981 numbers

Test #4:

score: 0
Accepted
time: 3816ms
memory: 85592kb

input:

666
775
98 357 198 407 409 200 454 585 319 622 366 264 710 91 765 78 32 528 335 101 469 204 312 382 276 613 231 342 327 324 441 544 413 299 494 393 349 611 211 702 165 297 320 284 401 530 317 567 142 742 447 482 662 126 506 273 362 328 555 416 206 604 589 305 99 114 291 131 386 75 670 280 704 189 43...

output:

11 20 20 20 19 18 18 18 18 18 18 18 18 18 18 18 18 17 16 16 16 16 16 16 16 16 16 16 16 16 16 15 14 14 14 14 13 12 12 12 12 12 12 12 12 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 8 8 8 8 7 6 6 6 6 6 6 6 6 6 6 6 6 ...

result:

ok 500000 numbers

Test #5:

score: -100
Time Limit Exceeded

input:

65
9836
5216 2035 5946 2744 9708 9116 1184 2000 4650 569 2428 585 3406 8146 6809 875 9131 9092 5998 2088 8393 9447 7766 4990 3903 7730 3426 6726 2029 4208 1546 4639 997 1428 2357 8630 7552 3531 7241 3530 4548 7310 3205 3508 9764 8929 4781 5702 3777 670 7384 1049 1707 4544 1637 9349 2427 3338 634 596...

output:

8 13 12 11 10 10 10 10 10 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 10 8 8 8 8 8 8 8 8 8 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6...

result: