Submission #61593279


Source Code Expand

#include<bits/stdc++.h>
namespace IO{
    template<typename T>
    void read(T &x){
        char ch=getchar();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getchar();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getchar();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    template <typename _Tp>
    void write(_Tp x) {
        if(x<0) x=(~x+1),putchar('-');
        if(x>9) write(x/10);
        putchar(x%10+'0');
    }
}
using namespace std;
using namespace IO;
const int N=5e5+5,mod=1e9+7,Inf=1e9;
int n,q,a[N],b[N],tot,rt[N];
struct PerSgtTree {
    #define mid ((l+r)>>1)
    int sum[N<<6],ls[N<<6],rs[N<<6],cnt;
    void modify(int &x,int p,int l,int r,int pos) {
        x=++cnt;
        sum[x]=sum[p]+1;
        ls[x]=ls[p]; rs[x]=rs[p];
        if(l==r) return ;
        if(pos<=mid) modify(ls[x],ls[p],l,mid,pos);
        else modify(rs[x],rs[p],mid+1,r,pos);
    }
    int query(int A,int B,int l,int r,int k) {
        if(l>=r) return l;
        int res=sum[ls[A]]-sum[ls[B]];
        if(res<k) return query(rs[A],rs[B],mid+1,r,k-res);
        else return query(ls[A],ls[B],l,mid,k);
    }
    int find(int A,int B,int l,int r,int k) {
        // printf("%d %d\n",l,r);
        if(l==r) return sum[A]-sum[B];
        int res=sum[rs[A]]-sum[rs[B]];
        if(k<=mid) return find(ls[A],ls[B],l,mid,k)+res;
        else return find(rs[A],rs[B],mid+1,r,k);
    }
}T;
int solve(int L,int R) {
    int l=1,r=(R-L+1)/2,ans=0;
    while(l<=r) {
        int Mid=(l+r)>>1;
        int p=T.query(rt[R],rt[L-1],1,Inf,Mid);
        int num=T.find(rt[R],rt[L-1],1,Inf,p*2);
        printf("%d %d %d\n",Mid,p,num);
        if(num>=Mid) l=Mid+1,ans=Mid;
        else r=Mid-1;
    }
    return ans;
}
int cmp(int x,int y) {
    return x<y;
} 
int check(int x) {
    for(int i=1;i<=x;i++) {
        int to=n-x+i;
        if(a[i]*2>a[to]) return 0;
    }
    return 1;
}
signed main() {
#ifndef KAxdd
#ifndef ONLINE_JUDGE
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#endif
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    sort(a+1,a+n+1,cmp);
    int l=1,r=n/2,ans=0;
    while(l<=r) {
        int Mid=(l+r)>>1;
        if(check(Mid)) l=Mid+1,ans=Mid;
        else r=Mid-1;
    }
    printf("%d\n",ans);
    // for(int i=1;i<=n;i++) T.modify(rt[i],rt[i-1],1,Inf,a[i]);
    // read(q);
    // while(q--) {
    //     int l,r; read(l,r);
    //     printf("%lld\n",solve(l,r));
    // }
    return 0;
}
/*
11
1 1 2 3 4 4 7 10 11 12 20
1
1 11

*/

Submission Info

Submission Time
Task E - Simultaneous Kagamimochi
User KAddx
Language C++ 20 (gcc 12.2)
Score 450
Code Size 2683 Byte
Status AC
Exec Time 33 ms
Memory 5828 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 41
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 02_handmade_36.txt, 02_handmade_37.txt, 02_handmade_38.txt, 02_handmade_39.txt, 02_handmade_40.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3876 KiB
00_sample_01.txt AC 1 ms 3800 KiB
00_sample_02.txt AC 1 ms 3800 KiB
01_random_03.txt AC 32 ms 5608 KiB
01_random_04.txt AC 32 ms 5760 KiB
01_random_05.txt AC 32 ms 5820 KiB
01_random_06.txt AC 32 ms 5616 KiB
01_random_07.txt AC 32 ms 5592 KiB
01_random_08.txt AC 4 ms 4084 KiB
01_random_09.txt AC 30 ms 5588 KiB
01_random_10.txt AC 17 ms 4884 KiB
01_random_11.txt AC 33 ms 5752 KiB
01_random_12.txt AC 31 ms 5604 KiB
01_random_13.txt AC 30 ms 5756 KiB
01_random_14.txt AC 32 ms 5612 KiB
01_random_15.txt AC 31 ms 5828 KiB
01_random_16.txt AC 31 ms 5760 KiB
01_random_17.txt AC 32 ms 5756 KiB
01_random_18.txt AC 32 ms 5608 KiB
01_random_19.txt AC 32 ms 5620 KiB
01_random_20.txt AC 32 ms 5692 KiB
01_random_21.txt AC 32 ms 5628 KiB
01_random_22.txt AC 32 ms 5692 KiB
01_random_23.txt AC 31 ms 5612 KiB
01_random_24.txt AC 31 ms 5824 KiB
01_random_25.txt AC 32 ms 5628 KiB
01_random_26.txt AC 32 ms 5628 KiB
01_random_27.txt AC 31 ms 5688 KiB
01_random_28.txt AC 32 ms 5756 KiB
01_random_29.txt AC 31 ms 5620 KiB
01_random_30.txt AC 31 ms 5540 KiB
01_random_31.txt AC 32 ms 5760 KiB
01_random_32.txt AC 31 ms 5568 KiB
01_random_33.txt AC 18 ms 4892 KiB
01_random_34.txt AC 24 ms 5176 KiB
01_random_35.txt AC 19 ms 5008 KiB
02_handmade_36.txt AC 1 ms 3680 KiB
02_handmade_37.txt AC 1 ms 3744 KiB
02_handmade_38.txt AC 29 ms 5568 KiB
02_handmade_39.txt AC 30 ms 5824 KiB
02_handmade_40.txt AC 17 ms 5736 KiB