1 solutions

  • 0
    @ 2024-12-11 0:09:07

    C :

    #include<stdio.h>
    #include<string.h>
    unsigned int a[15625010] = {0};
    int main()
    {
        int i,n,m,x;
        while(~scanf("%d%d",&n,&m))
        {
            memset(a,0,sizeof(a));
            for(i=0; i<n; i++)
            {
                scanf("%d",&x);
                a[ x/32 ] |= 1 << (x%32);
            }
            for(i=0; i<m; i++)
            {
                scanf("%d",&x);
                if( a[x/32] & (1 << (x%32)) )
                    printf("Yes\n");
                else
                    printf("No\n");
            }
    
        }
        return 0;
    }
    
    

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<time.h>
    #include<cstring>
    using namespace std;
    #define N 500000000
    
    unsigned a[N/32+5];
    
    int main(){
        //freopen("test.in", "r", stdin);
        //freopen("test.out","w", stdout);
        int d, x, y;
        int n, m;
      
        while( ~scanf("%d%d", &n, &m) ) {
            while(n--) scanf("%d", &d), x = d / 32, y = d % 32, a[x] |= (1<<y);
            while(m--) scanf("%d", &d), x = d / 32, y = d % 32, printf( ( a[x] & (1<<y) ) ? "Yes\n" : "No\n" );
            memset(a, 0, sizeof(a));
        }
        return 0;
    }
    
    
    • 1

    Information

    ID
    675
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By