QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#373462#5143. Quick SortSiilhouetteWA 51ms8040kbC++142.7kb2024-04-01 18:15:202024-04-01 18:15:21

Judging History

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

  • [2024-04-01 18:15:21]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:8040kb
  • [2024-04-01 18:15:20]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=500010;
int n,a[N];

struct SegmentTree{
    int maxi[N<<2],mini[N<<1];
#define maxi(x) maxi[x]
#define mini(x) mini[x]

    inline void build(int p,int l,int r)
    {
        if(l==r)return maxi(p)=mini(p)=a[l],void();
        int mid=l+r>>1;
        build(p<<1,l,mid),build(p<<1|1,mid+1,r);
        maxi(p)=max(maxi(p<<1),maxi(p<<1|1));
        mini(p)=min(mini(p<<1),mini(p<<1|1));
    }

    inline void change(int p,int l,int r,int d,int v)
    {
        if(l==r)return maxi(p)=mini(p)=v,void();
        int mid=l+r>>1;
        if(d<=mid)change(p<<1,l,mid,d,v);
        if(d>mid)change(p<<1|1,mid+1,r,d,v);
        maxi(p)=max(maxi(p<<1),maxi(p<<1|1));
        mini(p)=min(mini(p<<1),mini(p<<1|1));
    }

    inline int query(int p,int l,int r,int L,int R,int v,int op) //op==0 min arg(i){a[i]>=v}
    {//op==1 max arg(i){a[i]<=v)
    //    cout<<"query "<<p<<" "<<l<<" "<<r<<" "<<L<<" "<<R<<" "<<v<<" "<<op<<endl;
        if(l==r)
        {
            if(!op)return a[l]>=v?l:-1;
            else return a[l]<=v?l:-1;
        }/**/
        int mid=l+r>>1,res=-1;
        if(!op)
        {
            if(L<=mid&&maxi(p<<1)>=v)res=query(p<<1,l,mid,L,R,v,op);
            if(res==-1)res=query(p<<1|1,mid+1,r,L,R,v,op);
        }
        else
        {
            if(R>mid&&mini(p<<1|1)<=v)res=query(p<<1|1,mid+1,r,L,R,v,op);
            if(res==-1)res=query(p<<1,l,mid,L,R,v,op);
        }
        //if((~res1)&&(~res2))return op?max(res1,res2):min(res1,res2);
        //else return (~res1)?res1:res2;
        return res;
    }
}t;

int ans;
inline int parti(int *a,int l,int r)
{
    int mid=l+r>>1,piv=a[l+r>>1];
//    cout<<"parti "<<l<<" "<<r<<" "<<piv<<endl;;
    for(int i=l,j=r,ii,jj;;)
    {
        ii=t.query(1,1,n,i,mid,piv,0);
        jj=t.query(1,1,n,mid,j,piv,1);
//        cout<<"ii jj "<<ii<<" "<<jj<<endl;
        if(ii>=jj)return jj;
        ans++;swap(a[ii],a[jj]);
        t.change(1,1,n,ii,a[ii]);
        t.change(1,1,n,jj,a[jj]);
        i=ii,j=jj;
    }
}

inline void quisort(int *a,int l,int r)
{
    int p;
    if(l&&r&&l<r)
    {
        p=parti(a,l,r);
        //getchar();
        quisort(a,l,p);
        quisort(a,p+1,r);
        
    }
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        t.build(1,1,n);
        ans=0;
        quisort(a,1,n);
        printf("%d\n",ans);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 8016kb

input:

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

output:

1
4
7

result:

ok 3 number(s): "1 4 7"

Test #2:

score: 0
Accepted
time: 44ms
memory: 7900kb

input:

100000
4
3 4 2 1
5
5 4 1 3 2
4
3 1 4 2
4
4 2 1 3
4
1 3 2 4
4
4 2 3 1
4
3 2 1 4
5
1 2 3 4 5
5
5 2 3 1 4
5
1 3 5 4 2
5
4 3 2 1 5
5
3 4 2 1 5
5
5 4 3 2 1
4
3 4 2 1
5
4 2 5 1 3
5
4 1 5 2 3
4
3 4 1 2
4
2 1 3 4
5
4 3 2 5 1
4
4 2 1 3
5
3 1 5 2 4
4
4 1 2 3
5
1 5 2 4 3
5
4 1 3 5 2
5
4 2 3 5 1
5
1 2 3 4 5
5
4...

output:

3
4
3
2
1
1
1
0
2
2
2
3
2
3
2
3
2
1
3
2
4
3
2
3
2
0
4
2
4
1
3
2
3
2
2
1
3
1
1
2
4
3
2
3
1
1
1
3
3
3
4
4
2
3
3
2
3
3
3
2
1
1
2
3
1
3
1
1
3
4
2
2
4
1
1
3
2
2
2
2
1
3
4
4
3
4
2
2
1
3
2
3
2
3
3
2
1
4
2
3
4
1
2
2
3
2
2
3
2
2
2
2
4
1
2
3
2
2
2
2
3
2
3
4
3
2
3
4
2
4
1
3
2
3
4
3
3
4
1
2
4
3
2
4
2
3
3
1
2
2
...

result:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 51ms
memory: 8040kb

input:

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

output:

8
8
8
8
9
5
3
8
8
9
7
8
7
9
8
11
6
8
8
7
7
11
7
6
11
8
3
6
8
6
6
7
10
4
8
6
6
8
5
6
7
6
7
5
5
8
9
5
9
10
6
7
8
9
4
9
6
7
8
8
9
7
5
7
6
6
10
9
8
6
4
8
6
10
4
9
9
6
9
6
7
7
7
9
6
6
9
8
7
9
9
5
6
8
8
8
8
8
6
4
8
8
5
8
8
8
9
8
8
7
8
7
6
10
9
5
7
7
6
5
5
6
8
9
5
6
7
8
6
7
9
6
7
9
7
7
6
8
9
9
7
7
9
7
8
6
...

result:

wrong answer 11th numbers differ - expected: '9', found: '7'