結果

問題 No.728 ギブ and テイク
ユーザー annin256annin256
提出日時 2018-08-26 23:15:12
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2,140 ms / 3,000 ms
コード長 1,135 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 29,912 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-09-13 19:27:04
合計ジャッジ時間 16,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 75 ms
4,376 KB
testcase_14 AC 131 ms
4,380 KB
testcase_15 AC 52 ms
4,376 KB
testcase_16 AC 116 ms
4,376 KB
testcase_17 AC 106 ms
4,380 KB
testcase_18 AC 1,344 ms
5,844 KB
testcase_19 AC 1,456 ms
5,912 KB
testcase_20 AC 1,790 ms
6,228 KB
testcase_21 AC 1,563 ms
6,068 KB
testcase_22 AC 498 ms
4,652 KB
testcase_23 AC 306 ms
4,468 KB
testcase_24 AC 1,063 ms
5,408 KB
testcase_25 AC 1,056 ms
5,460 KB
testcase_26 AC 477 ms
4,516 KB
testcase_27 AC 2,140 ms
6,504 KB
testcase_28 AC 2,056 ms
6,504 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n, a[300000], L[300000], R[300000], b[100][3000], bc[100];

int cmp(const void *x, const void *y) {
  return *(int *)x - *(int *)y;
}

int gt(int *a, int n, int x) {
  int l = -1;
  int r = n;
  while (r - l > 1) {
    int m = (r + l) / 2;
    if (a[m] >= x) {
      r = m;
    } else {
      l = m;
    }
  }
  return n - r;
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &L[i], &R[i]);
    b[i / 3000][i % 3000] = a[i] + R[i];
    bc[i / 3000]++;
  }
  for (int i = 0; i < 100; i++) {
    qsort(b[i], bc[i], sizeof(int), cmp);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int j = i;
    while (j - 3000 >= 0 && a[j - 3000] >= a[i] - L[i]) j -= 3000;
    while (j - 1 >= 0 && a[j - 1] >= a[i] - L[i]) j -= 1;
    while (j < i) {
      if (j % 3000 == 0 && j + 3000 <= i) {
        ans += gt(b[j / 3000], bc[j / 3000], a[i]);
        j += 3000;
      } else {
        if (a[j] + R[j] >= a[i]) ans++;
        j += 1;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
0