結果

問題 No.206 数の積集合を求めるクエリ
ユーザー akakimidoriakakimidori
提出日時 2017-06-23 22:15:37
言語 C90
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,187 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 22,656 KB
実行使用メモリ 8,864 KB
最終ジャッジ日時 2024-04-10 11:44:30
合計ジャッジ時間 16,659 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
8,864 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 0 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 0 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 8 ms
6,944 KB
testcase_15 AC 9 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1,906 ms
6,940 KB
testcase_18 AC 484 ms
6,940 KB
testcase_19 AC 1,544 ms
6,944 KB
testcase_20 AC 12 ms
6,940 KB
testcase_21 AC 482 ms
6,940 KB
testcase_22 AC 1,070 ms
6,940 KB
testcase_23 AC 1,708 ms
6,940 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:49:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |   scanf("%d%d%d",&l,&m,&n);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
main.c:55:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     scanf("%d",&p);
      |     ^~~~~~~~~~~~~~
main.c:61:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |     scanf("%d",b+i);
      |     ^~~~~~~~~~~~~~~
main.c:65:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |   scanf("%d",&q);
      |   ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define get(p,n) ((p[(n)>>5]>>((n)&0x1F))&0x01)

void qsort8(int *a,int n){
  if(n<8) return;

  int p=rand()%n;
  int pivot=a[p];
  a[p]=a[0];
  int l=1;
  int r=n-1;
  while(l<=r){
    if(pivot>=a[l]){
      a[l-1]=a[l];
      l++;
    } else {
      int swap=a[r];
      a[r]=a[l];
      a[l]=swap;
      r--;
    }
  }
  a[r]=pivot;
  qsort8(a,r);
  qsort8(a,n-r-1);
  return;
}

void qqsort(int *a,int n){
  srand((unsigned)time(NULL));
  int i,j;
  for(i=1;i<n;i++){
    int p=a[i];
    j=i-1;
    while(j>=0 && a[j]>p){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=p;
  }
  return;
}

void run(void){
  int l,m,n;
  scanf("%d%d%d",&l,&m,&n);

  unsigned int *a=(unsigned int *)calloc(100000,sizeof(int));
  int i;
  for(i=0;i<l;i++){
    int p;
    scanf("%d",&p);
    a[p>>5]|=(1<<(p&0x1F));
  }

  int *b=(int *)malloc(sizeof(int)*m);
  for(i=0;i<m;i++){
    scanf("%d",b+i);
  }
  qqsort(b,m);
  int q;
  scanf("%d",&q);

  for(i=0;i<q;i++){
    int count=0;
    int j;
    for(j=0;j<m&&b[j]<=n-i;j++){
      count+=get(a,b[j]+i);
    }
    printf("%d\n",count);
  }

  return;
}

int main(void){
  run();
  return 0;
}
0