Submission #888172

# Submission time Handle Problem Language Result Execution time Memory
888172 2023-12-16T09:29:36 Z Macker Pairs (IOI07_pairs) C++17
12 / 100
162 ms 524288 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()

class Seg{
    vector<int> st;
    int len = 1;

public:
    Seg(int n){
        while(len < n) len *= 2;
        st.resize(len * 2, 0);
    }

    void add(int idx, int val, int i, int s, int e){
        if(idx < s || idx >= e) return;
        if(idx == s && s + 1 == e){
            st[i] += val;
            return;
        }
        add(idx, val, i * 2, s, (s + e) / 2);
        add(idx, val, i * 2 + 1, (s + e) / 2, e);
        st[i] = st[i * 2] + st[i * 2 + 1];
    }
    void add(int idx, int val){
        add(idx, val, 1, 0, len);
    }

    ll qry(int l, int r, int i, int s, int e){
        if(l >= e || s >= r) return 0;
        if(l <= s && e <= r) return st[i];
        return qry(l, r, i * 2, s, (s + e) / 2) + qry(l, r, i * 2 + 1, (s + e) / 2, e);
    }
    ll qry(int l, int r){
        return qry(l, r, 1, 0, len);
    }
};


int main()
{
    int b, n, d, m; cin >> b >> n >> d >> m;
    if(b == 1){
        vector<pair<int, int>> q;
        Seg st(m);
        for (int i = 0; i < n; i++) {
            int a; cin >> a;
            st.add(a, 1);
            q.push_back({a - d, a + d + 1});
        }
        ll res = 0;
        for (auto &[f, t] : q)
            res += st.qry(f, t) - 1;
        
        cout << res / 2 << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 162 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1748 KB Output is correct
2 Correct 26 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 104 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 97 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -