QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276727#6357. 排序SoyTony100 ✓1048ms8900kbC++143.1kb2023-12-06 10:07:192023-12-06 10:07:19

Judging History

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

  • [2023-12-06 10:07:19]
  • 评测
  • 测评结果:100
  • 用时:1048ms
  • 内存:8900kb
  • [2023-12-06 10:07:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
inline int read(){
    int x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}
int n,m,q,ans;
int a[maxn];
struct Question{
    int typ,l,r;
}b[maxn];
int id[maxn];
struct SegmentTree{
    #define mid ((l+r)>>1)
    #define lson rt<<1,l,mid
    #define rson rt<<1|1,mid+1,r
    int siz[maxn<<2],tag[maxn<<2];
    inline void push_up(int rt){
        siz[rt]=siz[rt<<1]+siz[rt<<1|1];
    }
    void build(int rt,int l,int r,int k){
        siz[rt]=0,tag[rt]=-1;
        if(l==r){
            id[l]=rt;
            if(a[l]>=k) siz[rt]=1;
            return;
        }
        build(lson,k),build(rson,k);
        push_up(rt);
    }
    inline void push_down(int rt,int l,int r){
        if(!tag[rt]){
            tag[rt<<1]=tag[rt<<1|1]=tag[rt];
            siz[rt<<1]=siz[rt<<1|1]=0;
            tag[rt]=-1;
        }
        if(tag[rt]==1){
            tag[rt<<1]=tag[rt<<1|1]=tag[rt];
            siz[rt<<1]=mid-l+1,siz[rt<<1|1]=r-mid;
            tag[rt]=-1;
        }
    }
    void update(int rt,int l,int r,int pl,int pr,int k){
        if(pl<=l&&r<=pr){
            if(!k) siz[rt]=0,tag[rt]=0;
            else siz[rt]=r-l+1,tag[rt]=1;
            return;
        }
        push_down(rt,l,r);
        if(pl<=mid) update(lson,pl,pr,k);
        if(pr>mid) update(rson,pl,pr,k);
        push_up(rt);
    }
    int query(int rt,int l,int r,int pl,int pr){
        if(pl<=l&&r<=pr) return siz[rt];
        push_down(rt,l,r);
        int res=0;
        if(pl<=mid) res+=query(lson,pl,pr);
        if(pr>mid) res+=query(rson,pl,pr);
        return res;
    }
    inline void output1(){ 
        for(int i=1;i<=n;++i){
            printf("%d %d %d\n",i,siz[id[i]],tag[id[i]]);
        }
    }
    inline void output2(int rt,int l,int r){
        printf("%d %d %d %d %d\n",rt,l,r,siz[rt],tag[rt]);
        if(l==r) return;
        output2(lson),output2(rson);
    }
    #undef mid
}S;
inline bool check(int x){
    S.build(1,1,n,x);
    //printf("%d\n",x);
    //S.output1();
    for(int i=1;i<=m;++i){
        int num0,num1;
        num1=S.query(1,1,n,b[i].l,b[i].r);
        num0=(b[i].r-b[i].l+1)-num1;
        //printf("%d %d\n",num0,num1);
        if(!b[i].typ){
            if(num0) S.update(1,1,n,b[i].l,b[i].l+num0-1,0);
            if(num1) S.update(1,1,n,b[i].r-num1+1,b[i].r,1);
        }
        else{
            if(num1) S.update(1,1,n,b[i].l,b[i].l+num1-1,1);
            if(num0) S.update(1,1,n,b[i].r-num0+1,b[i].r,0);
        }
        //S.output2(1,1,n);
    }
    return S.query(1,1,n,q,q);
}
int main(){
    n=read(),m=read();
    for(int i=1;i<=n;++i) a[i]=read();
    for(int i=1;i<=m;++i){
        b[i].typ=read(),b[i].l=read(),b[i].r=read();
    }
    q=read();
    int l=1,r=n;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)) ans=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 1ms
memory: 8068kb

input:

100 100
46 2 24 25 18 43 19 38 9 6 7 30 16 33 32 47 22 1 14 5 45 23 50 48 40 3 26 21 20 39 29 34 42 17 11 4 12 31 49 8 28 10 44 36 35 37 13 15 41 27 95 55 76 84 63 70 83 89 94 65 100 54 69 86 53 71 57 77 68 81 58 56 64 51 88 74 79 82 52 61 73 96 92 72 78 97 66 60 87 90 93 98 80 91 99 75 85 67 59 62
...

output:

62

result:

ok 1 number(s): "62"

Test #2:

score: 10
Accepted
time: 1ms
memory: 7924kb

input:

100 100
3 28 34 50 2 31 11 23 21 5 13 24 20 39 12 8 46 37 49 6 43 19 42 33 17 4 45 40 47 18 15 35 38 44 7 26 30 9 14 32 25 22 29 1 10 16 36 41 48 27 88 66 59 94 95 99 69 81 79 90 60 86 76 61 85 56 54 82 63 80 75 83 64 97 72 71 52 87 100 55 84 78 62 68 77 89 93 92 58 96 73 91 53 67 65 51 57 74 70 98
...

output:

16

result:

ok 1 number(s): "16"

Test #3:

score: 10
Accepted
time: 1ms
memory: 5884kb

input:

100 100
20 2 1 44 39 15 23 37 25 33 13 14 16 42 26 35 12 32 5 19 11 4 45 24 30 3 27 41 7 10 9 31 48 28 6 21 18 17 8 22 43 29 50 38 36 49 47 40 34 46 55 53 66 72 98 51 71 74 62 54 81 69 91 84 52 65 76 87 94 61 80 99 83 88 63 97 100 75 85 82 92 86 64 67 70 60 56 57 77 58 79 89 90 78 96 68 73 59 93 95
...

output:

21

result:

ok 1 number(s): "21"

Test #4:

score: 10
Accepted
time: 148ms
memory: 6180kb

input:

8050 22018
1 29 31 10 16 46 42 23 44 15 37 17 26 28 48 18 9 39 12 2 41 38 25 5 33 20 34 35 7 6 8 32 4 40 49 3 21 13 50 45 19 27 14 11 24 36 30 43 47 22 69 84 88 100 72 76 95 65 99 87 77 83 70 73 97 67 58 62 71 86 80 57 82 63 91 90 96 85 52 59 94 64 51 60 56 55 74 93 75 68 79 98 81 61 53 66 54 78 92 ...

output:

1622

result:

ok 1 number(s): "1622"

Test #5:

score: 10
Accepted
time: 119ms
memory: 7936kb

input:

1400 31558
11 16 45 42 41 50 10 47 24 38 13 27 43 46 22 39 23 29 32 33 49 25 21 28 14 4 34 8 17 36 48 6 1 35 12 30 44 19 2 40 5 15 18 7 9 26 3 20 31 37 67 57 94 76 66 88 85 86 54 89 79 80 63 74 75 69 78 96 87 91 97 95 61 73 55 62 64 65 92 93 59 99 52 71 53 70 60 100 84 68 58 77 56 90 83 51 72 82 98 ...

output:

1241

result:

ok 1 number(s): "1241"

Test #6:

score: 10
Accepted
time: 35ms
memory: 8084kb

input:

1650 7019
9 15 16 46 19 44 13 11 50 37 5 7 23 36 42 30 34 1 28 45 38 31 21 40 8 24 43 6 48 14 22 39 47 2 29 27 17 35 4 3 10 41 20 12 25 26 49 33 18 32 70 99 74 89 51 82 97 60 88 63 61 90 52 94 57 75 81 76 85 65 91 86 59 66 72 56 93 96 71 79 73 54 98 64 69 83 68 62 53 78 95 55 100 87 80 67 77 92 58 8...

output:

954

result:

ok 1 number(s): "954"

Test #7:

score: 10
Accepted
time: 146ms
memory: 6244kb

input:

8700 23581
7 42 44 23 38 25 50 37 20 18 21 3 34 19 11 22 12 17 40 4 30 15 39 28 13 27 1 32 31 24 49 45 33 5 26 43 16 14 2 46 48 10 36 29 8 35 41 9 6 47 92 78 88 66 93 61 63 60 98 64 75 82 59 52 97 70 79 56 90 81 94 57 67 80 100 89 55 99 68 95 86 76 91 62 54 53 83 69 85 72 77 84 96 58 65 73 87 74 71 ...

output:

283

result:

ok 1 number(s): "283"

Test #8:

score: 10
Accepted
time: 83ms
memory: 7892kb

input:

9150 13084
9 20 10 44 3 36 1 11 19 23 17 14 27 12 25 2 15 21 26 39 29 22 28 49 16 24 37 7 4 13 50 33 8 31 32 47 42 18 6 5 48 45 46 30 38 41 43 40 35 34 82 51 95 75 73 89 99 63 100 96 61 70 57 93 84 59 87 94 60 85 56 88 81 76 66 64 83 53 71 72 78 67 80 55 74 91 69 68 54 90 98 65 58 86 77 79 92 62 97 ...

output:

973

result:

ok 1 number(s): "973"

Test #9:

score: 10
Accepted
time: 1048ms
memory: 8900kb

input:

100000 100000
9 23 49 19 16 15 1 46 48 11 33 5 21 31 4 43 26 20 13 22 42 10 38 8 34 37 45 7 36 24 6 39 3 18 2 27 44 40 17 50 32 35 29 12 28 25 47 41 30 14 65 87 53 69 86 72 77 63 99 100 75 84 81 95 91 89 80 96 73 52 83 60 66 94 71 59 62 56 92 58 55 68 51 70 90 93 64 74 97 82 88 79 54 76 78 67 98 61 ...

output:

6922

result:

ok 1 number(s): "6922"

Test #10:

score: 10
Accepted
time: 1029ms
memory: 8384kb

input:

100000 100000
21 28 36 2 16 48 19 37 7 5 44 30 22 45 3 15 8 9 20 38 12 50 1 43 25 11 4 14 46 13 42 39 10 49 35 17 26 33 23 27 6 18 34 41 29 47 24 31 32 40 93 69 70 91 61 94 87 58 92 73 86 96 64 84 52 98 77 71 53 55 62 75 56 59 68 67 88 83 78 100 54 95 74 97 65 60 80 85 66 72 79 90 76 82 57 51 99 63 ...

output:

13716

result:

ok 1 number(s): "13716"