QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322494#5463. Range Closest Pair of Points QuerybobbilykingCompile Error//C++174.2kb2024-02-07 06:09:132024-02-07 06:09:14

Judging History

你现在查看的是最新测评结果

  • [2024-02-07 06:09:14]
  • 评测
  • [2024-02-07 06:09:13]
  • 提交

answer

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

constexpr ll N = 2.5e5 + 10;

constexpr ll BLK=9,K=28;

constexpr ll INF=1e18;

int n;

struct P{
    int x,y;
    P() {}
    P(int _x, int _y) : x(_x), y(_y) {}
    
    bool operator==(const P& o) const {
        return o.x == x and o.y == y;
    }
} a[N];

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(P p) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(p.y + splitmix64(p.x + FIXED_RANDOM));
    }
};


inline ll dis(const P&a,const P&b){
    return 1LL*(a.x-b.x)*(a.x-b.x)+1LL*(a.y-b.y)*(a.y-b.y);
}

struct rmq_t {
    // query the minimum from range [l, x] efficiently
    ll val[N], mi[N];

    inline void modify(int x,ll p){
        val[x] = min(val[x],p);
        mi[x>>BLK] = min(mi[x>>BLK],p);
    }

    inline ll query(int x){
        ll ret=INF;
        int X=x>>BLK;
        int NB=n>>BLK;

        for(int i=x;(i>>BLK)==X;i++) ret = min(ret, val[i]);
        for(int i=X+1;i<=NB;i++) ret = min(ret, mi[i]);
        return ret;
    }

    rmq_t() {
        fill(val, val+N, INF);
        fill(mi, mi+N, INF);
    }
} rmq;


struct Layer{
    int rad, ed = 0;

    unordered_map<P, int, custom_hash> pt2idx;

    vector<int>pool[N];
    int head = 1;

    int ask(int x,int y){ // ask for the index this belongs to, or 0 if not exist
        auto v = pt2idx.find(P(x, y));
        if (v == pt2idx.end()) return 0;
        return v->second;
    }

    int ins(int x,int y){
        auto& val = pt2idx[P(x, y)];
        if (!val) return val = ++ed;
        else return val;
    }

    void insert(int o){
        pool[ins(a[o].x>>rad,a[o].y>>rad)].push_back(o);
    }

    void search(int o){
        int A=a[o].x>>rad,B=a[o].y>>rad;
        for(int X=max(0, A-1);X<=A+1;X++)for(int Y=max(0, B-1);Y<=B+1;Y++){
            int O=ask(X,Y);
            if(!O)continue;
            while (pool[O].size() and pool[O].back() < head) pool[O].pop_back();

            for (auto lp: ranges::reverse_view(pool[O])) {
                if(lp>=o)break;

                ll cost=dis(a[o],a[lp]);
                ll distanceThreshold = 1LL<<rad*2; // 2^n * 2^n cell area

                if(cost >= distanceThreshold)continue;
                ll distanceThresholdOfPreviousLayer = 1ll<<(rad-1)*2;
                if (cost < distanceThresholdOfPreviousLayer) {
                    if(head<=lp)head=lp+1;
                    continue;
                }

                rmq.modify(lp,cost);
            }
        }
    }
} layer[K];


int main(){

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(20);

    cin >> n; G(m)
    F(i, 1, n+1) cin >> a[i].x >> a[i].y;
    
    vector<vector<pl>> queries(n+1);

    F(i, 1, m+1) {
        G(l) G(r)
        queries[r].emplace_back(l, i);
    }

    vl ans(m+1);

    F(i, 0, K) layer[i].rad = i+1;
     F(j, 0, K) FD(i, n, 0) {
        layer[j].insert(i);
    }

    F(i, 1, n+1) {
        F(j, 0, K) {
            if (j) layer[j].head = max(layer[j].head, layer[j-1].head);
            layer[j].search(i);
        }

        for (auto [lp, qidx]: queries[i]) {
            if(lp<layer[0].head)
                ans[qidx]=0;
            else 
                ans[qidx]=rmq.query(lp);
        }
    }

    F(i, 1, m+1) cout << ans[i] << '\n'; 
}

Details

answer.code: In member function ‘void Layer::search(int)’:
answer.code:117:27: error: ‘ranges’ has not been declared
  117 |             for (auto lp: ranges::reverse_view(pool[O])) {
      |                           ^~~~~~