Language: C++

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define N_MAX (1<<18)
#define INF 1000000000000000000LL

struct segmn{
  long long nn;
  long long dat[(2 * N_MAX) - 1];

  void init(long long n1){
    nn = 1;

    while(nn < n1)nn *= 2;

    for(long long i = 0; i < 2 * nn - 1; i++){
      dat[i] = INF;
    }
  }

  void update(long long k, long long a){
    k += nn - 1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  long long query(long long a, long long b, long long k, long long l, long long r){
    if(r <= a || b <= l)return INF;

    if(a <= l && r <= b){
      return dat[k];
    }
    else{
      long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }

  long long query(long long a, long long b){
    return query(a,b,0,0,nn);
  }
}segmn1,segmn2;

pair<ll,ll> d1[200100];
pair<ll,ll> d2[200100];

vector<int> uf, usz;
int nc;
  
void init(int n){
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;

  for(int i = 0; i < uf.size(); i++){
    uf[i] = i;
  }
}
  
int find(int a){
  return (uf[a] == a) ? a : uf[a] = find(uf[a]);
}
  
void union_(int a, int b){
  a = find(a);
  b = find(b);
  
  if(a != b){
    if(usz[a] >= usz[b]){
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}
  
int check(int a, int b){
  return (find(a) == find(b)) ? 1 : 0;
}
  
int get_size(int a){
  return usz[find(a)];
}

long long minST(vector<pair<long long,pair<long long, long long> > > &v, long long V){
  init(V);
  long long ret = 0;
  sort(v.begin(),v.end());
  for(long long i = 0; i < v.sz; i++){
    long long from = v[i].se.fi;
    long long to = v[i].se.se;
    long long cost = v[i].fi;
    if(check(from,to)==0){
      union_(from,to);
      ret += cost;
    }
  }
  return ret;
}

int main() {
  ll n,d;
  cin>>n>>d;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  rep(i,0,n){
    segmn1.update(i,d*i+v[i]);
  }
  per(i,0,n){
    segmn2.update(i,d*(n-1-i)+v[i]);
  }
  vector<pair<long long,pair<long long, long long> > > vv;
  rep(i,0,n-1){
    ll mn1 = segmn1.query(i+1,n);
    long long low = i+1;
    long long high = n-1;
    
    while(low < high){
      long long mid = (high + low + 1) >> 1;
    
      if(mn1 == segmn1.query(i+1,mid+1)){
        low = mid;
      }
      else{
        high = mid - 1;
      }
    }
    d1[i] = mp(low,mn1);
    vv.pb(mp(mn1,mp(i,low)));
  }
  rep(i,1,n){
    ll mn2 = segmn2.query(0,i);
    long long low = 0;
    long long high = i-1;
    
    while(low < high){
      long long mid = (high + low) >> 1;
    
      if(mn2 == segmn2.query(0,mid+1)){
        high = mid;
      }
      else{
        low = mid + 1;
      }
    }
    d2[i] = mp(low,mn2);
    vv.pb(mp(mn2,mp(i,low)));
  }
  printf("%lld\n", minST(v,n+1));
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:195:26: error: invalid initialization of reference of type 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >&' from expression of type 'std::vector<long long int>'
  195 |   printf("%lld\n", minST(v,n+1));
      |                          ^
a.cc:127:71: note: in passing argument 1 of 'long long int minST(std::vector<std::pair<long long int, std::pair<long long int, long long int> > >&, long long int)'
  127 | long long minST(vector<pair<long long,pair<long long, long long> > > &v, long long V){
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^