結果

問題 No.728 ギブ and テイク
コンテスト
ユーザー 梧桐
提出日時 2026-01-27 03:20:43
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
結果
TLE  
実行時間 -
コード長 1,002 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 971 ms
コンパイル使用メモリ 107,180 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2026-01-27 03:20:51
合計ジャッジ時間 7,138 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
typedef long long LL;
 
const int N = 30010;
 
struct House {
    int x, l, r;
};
 
LL ans;
House h[N];
int n, a[N];
set<int> s[N];
map<int, int> mm;
 
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        h[i].x = a[i];
        mm[a[i]] = i;
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &h[i].l, &h[i].r);
        h[i].l = h[i].x - h[i].l, h[i].r = h[i].x + h[i].r;
    }
 
    sort(a + 1, a + n + 1);
 
    for (int i = 1; i <= n; ++i) {
        for (int j = lower_bound(a + 1, a + n + 1, h[i].l) - a; j <= upper_bound(a + 1, a + n + 1, h[i].r) - a - 1; ++j) {
            if (i == j) continue;
            s[mm[a[j]]].insert(i);
        }
    }
 
    for (int i = 1; i <= n; ++i) {
        for (auto e : s[i]) {
            if (s[e].count(i)) ++ans;
        }
    }
 
    printf("%lld\n", ans / 2);
 
    return 0;
}
0