結果

問題 No.728 ギブ and テイク
コンテスト
ユーザー 梧桐
提出日時 2026-01-27 00:53:17
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
TLE  
実行時間 -
コード長 1,075 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,318 ms
コンパイル使用メモリ 111,528 KB
実行使用メモリ 396,708 KB
最終ジャッジ日時 2026-01-27 00:53:26
合計ジャッジ時間 8,029 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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() {
    // freopen("candy.in", "r", stdin);
    // freopen("candy.out", "w", stdout);

    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