結果

問題 No.206 数の積集合を求めるクエリ
ユーザー akakimidoriakakimidori
提出日時 2017-06-23 22:19:14
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 6,158 ms / 7,000 ms
コード長 1,206 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 22,528 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 12:00:04
合計ジャッジ時間 32,957 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,816 KB
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 0 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 0 ms
6,940 KB
testcase_11 AC 0 ms
6,940 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 6 ms
6,944 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 32 ms
6,940 KB
testcase_18 AC 16 ms
6,944 KB
testcase_19 AC 28 ms
6,944 KB
testcase_20 AC 10 ms
6,940 KB
testcase_21 AC 18 ms
6,940 KB
testcase_22 AC 21 ms
6,944 KB
testcase_23 AC 31 ms
6,940 KB
testcase_24 AC 6,158 ms
6,944 KB
testcase_25 AC 5,762 ms
6,940 KB
testcase_26 AC 3,092 ms
6,940 KB
testcase_27 AC 2,555 ms
6,940 KB
testcase_28 AC 5,732 ms
6,944 KB
testcase_29 AC 3,777 ms
6,940 KB
testcase_30 AC 4,264 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:50:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |   scanf("%d%d%d",&l,&m,&n);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
main.c:56:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |     scanf("%d",&p);
      |     ^~~~~~~~~~~~~~
main.c:62:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |     scanf("%d",b+i);
      |     ^~~~~~~~~~~~~~~
main.c:66:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |   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+r+1,n-r-1);
  return;
}

void qqsort(int *a,int n){
  srand((unsigned)time(NULL));
  qsort8(a,n);
  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