Language: C++

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e6+10;
pair<long long int,int>seg[4*maxn];
pair<long long int,int>seg2[4*maxn];
int a[maxn];
long long int dp[2][maxn];
int n;
int e;
int d;
void update(int id,int l,int r,int l2,int r2,long long int val){
if(l>=r2||r<=l2){
	return;
}	
if(l2<=l&&r<=r2&&r-l==1){
		seg[id]={val,l2};
		return ;
}
int mid=(l+r)>>1;
update(id<<1,l,mid,l2,r2,val);
update((id<<1)|1,mid,r,l2,r2,val);
seg[id]=min(seg[id<<1],seg[(id<<1)|1]);
}
pair<long long int,int>get(int id,int l,int r,int l2,int r2){
	if(l>=r2||r<=l2){
		return {(long long int)1e18+10,100000};
	}
	if(l2<=l&&r<=r2){
		return seg[id];
	}
	int mid=(l+r)>>1;
	return min(get(id<<1,l,mid,l2,r2),get((id<<1)|1,mid,r,l2,r2));
}
void update2(int id,int l,int r,int l2,int r2,long long int val){
if(l>=r2||r<=l2){
	return;
}	
if(l2<=l&&r<=r2&&r-l==1){
		seg2[id]={val,l2};
		return ;
}
int mid=(l+r)>>1;
update2(id<<1,l,mid,l2,r2,val);
update2((id<<1)|1,mid,r,l2,r2,val);
seg2[id]=min(seg2[id<<1],seg2[(id<<1)|1]);
}
pair<long long int,int>get2(int id,int l,int r,int l2,int r2){
	if(l>=r2||r<=l2){
		return {(long long int)1e18+10,100000};
	}
	if(l2<=l&&r<=r2){
		return seg2[id];
	}
	int mid=(l+r)>>1;
	return min(get2(id<<1,l,mid,l2,r2),get2((id<<1)|1,mid,r,l2,r2));
}
inline void input();
int32_t main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	input();
}
inline void input(){
	cin>>n>>e>>d;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<4*maxn;i++){
		seg[i]={(long long)1e18,(int)1e9};
		seg2[i]={(long long)1e18,(int)1e9};
	}
	for(int i=0;i<n;i++){
		if(i==0){
			dp[0][i]=a[i];
			dp[1][i]=a[i];
			dp[1][i]+=d;
		}
		else{
		int l=0;
		int r=i;
		while(l!=r-1){
			int mid=(l+r)>>1;
			if(2*(a[i]-a[mid])>=d){
				l=mid;
			}
			else{
				r=mid;
			}
		}
		if(2*(a[i]-a[0])<d){
			r=0;
		}
		if(2*(a[i]-a[i-1])>=d){
			l=i-1;
		}
	//	cout<<l<<": "<<r<<" "<<i<<endl;
		pair<long long int,int>p=get(1,0,n,0,l+1);
		//cout<<l<<endl;
		pair<long long int,int>w=get2(1,0,n,r,i);
		dp[0][i]=dp[1][i-1]+(a[i]-a[i-1]);
		dp[1][i]=(long long int)1e18+10;
		if(2*(a[i]-a[0])>=d){
			dp[1][i]=(dp[0][p.second]+1ll*3*(a[i]-a[p.second]));
		}
		if(2*(a[i]-a[i-1])<d){
			dp[1][i]=min(dp[1][i],(long long)(dp[0][w.second]+d+1ll*2*(a[i]-a[w.second])));
		}
		if(dp[1][i-1]+a[i]-a[i-1]+d<=dp[1][i]){
			dp[1][i]=(long long)(dp[1][i-1]+a[i]-a[i-1]+d);
		}
	}
	//	cout<<dp[0][i]<<" "<<dp[1][i]<<endl;
		//cout<<i<<endl;
		update(1,0,n,i,i+1,(long long)(dp[0][i]+1ll*3*(e-a[i])));
		update2(1,0,n,i,i+1,(long long)(dp[0][i]+1ll*2*(e-a[i])));
	}
	cout<<dp[1][n-1]+(e-a[n-1]);
} 

Compiler output:
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:5:16: note: in expansion of macro 'int'
    5 | pair<long long int,int>seg[4*maxn];
      |                ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:5:16: note: in expansion of macro 'int'
    5 | pair<long long int,int>seg[4*maxn];
      |                ^~~
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:6:16: note: in expansion of macro 'int'
    6 | pair<long long int,int>seg2[4*maxn];
      |                ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:6:16: note: in expansion of macro 'int'
    6 | pair<long long int,int>seg2[4*maxn];
      |                ^~~
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:8:11: note: in expansion of macro 'int'
    8 | long long int dp[2][maxn];
      |           ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:8:11: note: in expansion of macro 'int'
    8 | long long int dp[2][maxn];
      |           ^~~
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:12:56: note: in expansion of macro 'int'
   12 | void update(int id,int l,int r,int l2,int r2,long long int val){
      |                                                        ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:12:56: note: in expansion of macro 'int'
   12 | void update(int id,int l,int r,int l2,int r2,long long int val){
      |                                                        ^~~
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:25:16: note: in expansion of macro 'int'
   25 | pair<long long int,int>get(int id,int l,int r,int l2,int r2){
      |                ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:25:16: note: in expansion of macro 'int'
   25 | pair<long long int,int>get(int id,int l,int r,int l2,int r2){
      |                ^~~
a.cc: In function 'std::pair<long long int, long long int> get(long long int, long long int, long long int, long long int, long long int)':
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:27:36: note: in expansion of macro 'int'
   27 |                 return {(long long int)1e18+10,100000};
      |                                    ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:27:36: note: in expansion of macro 'int'
   27 |                 return {(long long int)1e18+10,100000};
      |                                    ^~~
a.cc: At global scope:
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:35:57: note: in expansion of macro 'int'
   35 | void update2(int id,int l,int r,int l2,int r2,long long int val){
      |                                                         ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:35:57: note: in expansion of macro 'int'
   35 | void update2(int id,int l,int r,int l2,int r2,long long int val){
      |                                                         ^~~
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:48:16: note: in expansion of macro 'int'
   48 | pair<long long int,int>get2(int id,int l,int r,int l2,int r2){
      |                ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:48:16: note: in expansion of macro 'int'
   48 | pair<long long int,int>get2(int id,int l,int r,int l2,int r2){
      |                ^~~
a.cc: In function 'std::pair<long long int, long long int> get2(long long int, long long int, long long int, long long int, long long int)':
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:50:36: note: in expansion of macro 'int'
   50 |                 return {(long long int)1e18+10,100000};
      |                                    ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:50:36: note: in expansion of macro 'int'
   50 |                 return {(long long int)1e18+10,100000};
      |                                    ^~~
a.cc: In function 'void input()':
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:97:32: note: in expansion of macro 'int'
   97 |                 pair<long long int,int>p=get(1,0,n,0,l+1);
      |                                ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:97:32: note: in expansion of macro 'int'
   97 |                 pair<long long int,int>p=get(1,0,n,0,l+1);
      |                                ^~~
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:99:32: note: in expansion of macro 'int'
   99 |                 pair<long long int,int>w=get2(1,0,n,r,i);
      |                                ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:99:32: note: in expansion of macro 'int'
   99 |                 pair<long long int,int>w=get2(1,0,n,r,i);
      |                                ^~~
a.cc:2:13: error: 'long long long' is too long for GCC
    2 | #define int long long
      |             ^~~~
a.cc:101:37: note: in expansion of macro 'int'
  101 |                 dp[1][i]=(long long int)1e18+10;
      |                                     ^~~
a.cc:2:18: error: 'long long long' is too long for GCC
    2 | #define int long long
      |                  ^~~~
a.cc:101:37: note: in expansion of macro 'int'
  101 |                 dp[1][i]=(long long int)1e18+10;
      |                                     ^~~