Submission #634176

#TimeUsernameProblemLanguageResultExecution timeMemory
634176Spade1Pairs (IOI07_pairs)C++14
60 / 100
32 ms3572 KiB
#include<bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

const int N = 2e5 + 10;

int a[N], fw[N];
pii c[N], e[N];

void update1(int i, int val) {
    if (i == 0) {
        fw[i] += val;
        return;
    }
    for (; i < N; i += i&-i) {
        fw[i] += val;
    }
}

int query1(int i) {
    if (i == 0) {
        return fw[i];
    }
    int ret = 0;
    for (; i > 0; i -= i&-i) {
        ret += fw[i];
    }
    return ret;
}

void solve() {
    int b, n, d, m; cin >> b >> n >> d >> m;
    ll ans = 0;
    if (b == 1) {
        for (int i = 0; i < n; ++i) cin >> a[i];
        sort(a, a+n);
        int l = 0;
        for (int i = 1; i < n; ++i) {
            while (a[i] - a[l] > d) l++;
            ans += (i-l);
        }
    }
    else if (b == 2) {
        for (int i = 0; i < n; ++i) cin >> c[i].st >> c[i].nd;
        for (int i = 0; i < n; ++i) {
            e[i].st = c[i].st - c[i].nd;
            e[i].nd = c[i].st + c[i].nd;
        }
        sort(e, e+n);
        int l = 0;
        update1(e[0].nd, 1);
        for (int i = 1; i < n; ++i) {
            while (e[i].st - e[l].st > d) {
                update1(e[l].nd, -1);
                l++;
            }
            ans += (query1(e[i].nd + d) - query1(max(0, e[i].nd - d - 1)));
            update1(e[i].nd, 1);
        }
    }
    else if (b == 3) {

    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...