Submission #1089593

# Submission time Handle Problem Language Result Execution time Memory
1089593 2024-09-16T18:49:04 Z BLOBVISGOD Pairs (IOI07_pairs) C++17
85 / 100
129 ms 10336 KB
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct fentree{
    vi a;
    fentree(int n) : a(n+1) {}
    void add(int i, int v){
        for(i++; i<sz(a); i+= i&(-i)) a[i]+=v;
    }

    // [0,r)
    int get(int r){
        int ans = 0;
        for(;r>0; r-=r&(-r)) ans += a[r];
        return ans;
    }
};

void trans(int& x, int& y, int B){
    int nx = x+y;
    y = B+y-x;
    x = nx;
}

int main(){
    cin.tie(NULL),cin.sync_with_stdio(false);
    
    int b,n,d,m; cin >> b >> n >> d >> m;
    ll ans = 0;
    if (b==1){
        vi a(n);
        rep(i,0,n) cin >> a[i];
        sort(all(a)); 
        for(auto c : a){
            int lo = lower_bound(all(a),c-d)-begin(a);
            int hi = upper_bound(all(a),c+d)-begin(a); hi--;
            // one element is c itself, so closed interval counts;
            ans += max(0,hi-lo);
        }
    }else if (b==2){
        int B = 75005;

        struct event{
            // type 1 = add/remove, type 0 = update
            int x, y, mul, type;
            bool operator<(event b){
                return x<b.x or (x==b.x and type < b.type);
            }
        };
        int at = 0;
        vector<event> E(n*5);
        ans -= n;

        while(n--){
            int x,y; cin >> x >> y;
            trans(x,y,B);
            E[at++] = {x,y,1,0};
            E[at++] = {x+d,y+d+1,1,1}; // assume halfopen queries in fentree, closed in events
            E[at++] = {x-d-1,y+d+1,-1,1};
            E[at++] = {x+d,y-d,-1,1};
            E[at++] = {x-d-1,y-d,1,1};
        }

        fentree fen(B*2+1);

        sort(all(E));
        for(auto e : E){
            if (e.type==0){
                fen.add(e.y,e.mul);
            }else{
                ans += e.mul*fen.get(e.y);
            }
        }
    }else{
        int B = 77;
        vector<vector<vector<int>>> a(B+1,vvi(B*2+1,vi(B*2+1)));
        vector<array<int,3>> qs(n);
        rep(i,0,n) rep(j,0,3) cin >> qs[i][j];

        for(auto [x,y,z] : qs){
            trans(y,z,B);
            a[x][y][z]++;
        }

        rep(i,0,sz(a)) rep(j,0,sz(a[0])) rep(k,0,sz(a[0])-1) a[i][j][k+1] += a[i][j][k];
        rep(i,0,sz(a)) rep(j,0,sz(a[0])-1) rep(k,0,sz(a[0])) a[i][j+1][k] += a[i][j][k];

        auto get = [&](int x,int y, int z) -> int {
            x = max(0,min(x,B));
            y = max(0,min(y,B*2));
            z = max(0,min(z,B*2));
            return a[x][y][z];
        };

        for (auto [x,y,z] : qs){
            trans(y,z,B);
            rep(i,0,B){
                int nd = d-abs(x-i);
                if (nd<0) continue;
                ans += get(i,y+nd,z+nd) - get(i,y-nd-1,z+nd) - get(i,y+nd,z-nd-1) + get(i,y-nd-1,z-nd-1);
            }
            ans --;
        }
    }

    cout << ans/2 << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1116 KB Output is correct
2 Correct 11 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1624 KB Output is correct
2 Correct 15 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1624 KB Output is correct
2 Correct 16 ms 1628 KB Output is correct
3 Correct 18 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Runtime error 2 ms 1916 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 9304 KB Output is correct
2 Correct 44 ms 9556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 9564 KB Output is correct
2 Correct 47 ms 9564 KB Output is correct
3 Correct 45 ms 9560 KB Output is correct
4 Correct 47 ms 9624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 10008 KB Output is correct
2 Incorrect 61 ms 9816 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8280 KB Output is correct
2 Correct 6 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 10076 KB Output is correct
2 Correct 38 ms 10072 KB Output is correct
3 Correct 48 ms 10072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 10328 KB Output is correct
2 Correct 120 ms 10328 KB Output is correct
3 Correct 60 ms 10336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 10328 KB Output is correct
2 Correct 129 ms 10328 KB Output is correct
3 Correct 60 ms 10332 KB Output is correct