Submission #714083

# Submission time Handle Problem Language Result Execution time Memory
714083 2023-03-23T21:32:16 Z SlavicG Pairs (IOI07_pairs) C++17
30 / 100
4000 ms 2888 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;
    for(int i = r + offset; i >= 1; i -= i & -i) ans += fen[i];
    for(int i = l + offset - 1; i >= 1; --i) ans -= fen[i];
    return ans;
}

void solve() {
    int b, n, d, m; cin >> b >> n >> d >> m;
    if(b == 1) {
        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 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1108 KB Output is correct
2 Correct 15 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1112 KB Output is correct
2 Correct 17 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1108 KB Output is correct
2 Correct 21 ms 1108 KB Output is correct
3 Correct 17 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 1456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 2512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4078 ms 2416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4067 ms 2888 KB Time limit exceeded
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 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 472 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -