Submission #714086

# Submission time Handle Problem Language Result Execution time Memory
714086 2023-03-23T21:36:09 Z SlavicG Pairs (IOI07_pairs) C++17
0 / 100
38 ms 3040 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long

#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

#define int long long
const int N = 2e6 + 10, offset = 3e5;
int fen[N];
void modif(int u, int val) {
    for(int i = u + offset; i < N; i += i & -i) fen[i] += val;
}
int query(int l, int r) {
    int ans = 0;
    r = min(r + offset, N - 1);
    l = max(0LL, l + offset - 1);
    for(int i = r; i >= 1; i -= i & -i) ans += fen[i];
    for(int i = l; i >= 1; i -= i & -i) ans -= fen[i];
    return ans;
}

void solve() {
    int b, n, d, m; cin >> b >> n >> d >> m;
    if(b == 1) {
        assert(false);
        vector<int> a(n);
        for(int i = 0; i < n; ++i) cin >> a[i];
        sort(all(a));
        int ans = 0;
        for(int i = 0; i < n; ++i) {
            int j = upper_bound(all(a), a[i] + d) - a.begin();
            ans += j - i - 1;
        } 
        cout << ans << "\n";
    } else if(b == 2) {
        vector<pair<int, int>> a;
        for(int i = 0; i < n; ++i) {
            int x, y; cin >> x >> y;
            a.pb({x + y, x - y});
        }
        queue<int> q;
        sort(all(a));
        int ans = 0;
        for(int i = 0; i < n; ++i) {
            while(!q.empty() && abs(a[i].first - a[q.front()].first) > d) {
                modif(a[i].second, -1);
                q.pop();
            }
            ans += query(a[i].second - d, a[i].second + d);
            q.push(i);
            modif(a[i].second, 1);
        }
        cout << ans << "\n";
    } else {
        assert(false);
    }
}   
 
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 2496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 2508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 3040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -