#include <bits/stdc++.h>
using ll = long long;
using namespace std;
struct el{
ll w, a, b;
};
struct dsu{
vector<int> p; vector<int> sz;
dsu(int n){
p.resize(n);
sz.resize(n, 1);
for(int i= 0; i<n; i++) p[i] = i;
}
int find(int a){
return p[a] == a ? a : p[a] = find(p[a]);
}
void merge(int a, int b){
a = find(a); b = find(b);
if(a==b) return;
if(sz[a] < sz[b]) swap(a, b);
p[b] = a;
sz[a]+=sz[b];
}
};
std::vector<long long> calculate_costs( std::vector<int> W, std::vector<int> A, std::vector<int> B, std::vector<int> E){
int n = W.size();
vector<el> v(n);
for(int i = 0; i<n; i++) v[i] = el{W[i], A[i], B[i]};
sort(v.begin(), v.end(), [](el a, el b){return a.w<b.w;});
vector<array<int, 2>> e(E.size());
for(int i= 0; i<E.size(); i++) e[i] = {E[i], i};
sort(e.begin(), e.end());
vector<ll> sol(E.size(), 0);
priority_queue<array<ll, 2>> pq;
for(int i= 0; i<n; i++){
pq.push({v[i].w-v[i+1].w, i});
}
dsu ds(n);
ll sl = 0;
for(int i = 0; i<n; i++) sl ++;
for(auto [d, j]: e){
while(!pq.empty() && -pq.top()[0]<=d){
int i = pq.top()[1];
pq.pop();
int a = ds.find(i);
int b = ds.find(i+1);
sl -= (ds.sz[a]&1) + (ds.sz[b]&1);
sl += (ds.sz[a]+ds.sz[b])&1;
ds.merge(a, b);
}
sol[j] = sl;
}
return sol;
/* for(int j = 0; j<E.size(); j++){
int d = E[j];
int curr_l = 0;
ll curr_mn = LLONG_MAX;
ll sm = 0;
for(int i= 0; i<n; i++){
curr_l++;
if(curr_l&1 || (i<n-1 && v[i+1].w-v[i-1].w <= d)) curr_mn = min(curr_mn, v[i].a-v[i].b);
sm += v[i].b;
if(i == n-1 || v[i+1].w-v[i].w > d){
if(curr_l&1) sol[j] += sm+curr_mn;
else sol[j] += sm;
sm = 0;
curr_l = 0;
curr_mn = LLONG_MAX;
}
}
}
return sol;*/
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |