結果

問題 No.728 ギブ and テイク
コンテスト
ユーザー annin256
提出日時 2018-08-26 23:11:23
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,122 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 386 ms
コンパイル使用メモリ 39,496 KB
最終ジャッジ日時 2026-02-22 01:32:33
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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