Re: [闲聊] 每日leetcode

楼主: sixB (6B)   2024-12-23 23:47:48
要去洗澡
等等再来看solution怎么写的
class Solution {
public:
vector<int> leftmostBuildingQueries(vector<int>& H, vector<vector<int>>& Q) {
// range: val [1, mx]
// get min idx
int n = H.size(), m = Q.size();
// seperate H
vector<int> sp(n);
for(int i = 0; i < n; i++){
sp[i] = i;
}
ranges::sort(sp, [&](int& a, int& b){return H[a] < H[b]; });
int cur = -1, cnt = 1;
for(int& i: sp){
if(H[i] == cur) H[i] = cnt;
else{
cur = H[i];
cnt++;
H[i] = cnt;
}
}
int mx = cnt * 4 + 1;
vector<int> tree(mx + 1, INT_MAX);
vector<int> order(m), res(m, -1);
// Q[i][1] order
for(int i = 0; i < m; i++){
if(Q[i][0] > Q[i][1]) swap(Q[i][0], Q[i][1]);
order[i] = i;
}
ranges::sort(order, [&](int& a, int& b){ return Q[a][1] < Q[b][1]; });
for(int i = n-1, oi = m-1; i >= 0, oi >= 0; i

Links booklink

Contact Us: admin [ a t ] ucptt.com