結果

問題 No.728 ギブ and テイク
ユーザー annin256annin256
提出日時 2018-08-26 23:11:23
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,122 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 29,744 KB
実行使用メモリ 6,600 KB
最終ジャッジ日時 2023-09-13 19:26:46
合計ジャッジ時間 22,413 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 31 ms
4,376 KB
testcase_14 AC 58 ms
4,376 KB
testcase_15 AC 21 ms
4,376 KB
testcase_16 AC 50 ms
4,376 KB
testcase_17 AC 44 ms
4,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 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[600][600], bc[600];

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

int gt(int *a, int n, int x) {
  int l = 0;
  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 / 600][i % 600] = a[i] + R[i];
    bc[i / 600]++;
  }
  for (int i = 0; i < 600; 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 - 600 >= 0 && a[j - 600] >= a[i] - L[i]) j -= 600;
    while (j - 1 >= 0 && a[j - 1] >= a[i] - L[i]) j -= 1;
    while (j < i) {
      if (j % 600 == 0 && j + 600 <= i) {
        ans += gt(b[j / 600], bc[j / 600], a[i]);
        j += 600;
      } else {
        if (a[j] + R[j] >= a[i]) ans++;
        j += 1;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
0