結果
| 問題 | 
                            No.728 ギブ and テイク
                             | 
                    
| コンテスト | |
| ユーザー | 
                             annin256
                         | 
                    
| 提出日時 | 2018-08-26 23:11:23 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,122 bytes | 
| コンパイル時間 | 524 ms | 
| コンパイル使用メモリ | 30,976 KB | 
| 実行使用メモリ | 14,008 KB | 
| 最終ジャッジ日時 | 2024-07-01 04:02:53 | 
| 合計ジャッジ時間 | 22,377 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 15 WA * 9 TLE * 2 -- * 4 | 
ソースコード
#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;
}
            
            
            
        
            
annin256