Language: C++

#include<iostream>
#include<cstdio>
#include<queue>
#define ll long long
using namespace std;
inline ll read()
{
	ll r,s=0,c;
	for(;!isdigit(c=getchar());s=c);
	for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);
	return s^45?r:-r;
}
const int N=1000010<<6,M=1000010<<6;
const ll inf=1e18;
int n,m;
struct edge
{
	int to,next;
	ll val;
}mem[M];
int head[N],cnt=1;
inline void add(int u,int v,ll val)
{
	mem[++cnt].next=head[u];
	mem[cnt].to=v;
	mem[cnt].val=val;
	head[u]=cnt;
}
struct tree
{
	int l,r,id;
}t1[N<<2],t2[N<<2];
int tot;
void build1(int rt,int l,int r)
{
	t1[rt].l=l,t1[rt].r=r;
	if(l==r)
	{
		t1[rt].id=l;
		return;
	}
	t1[rt].id=++tot;
	int mid=(l+r)>>1;
	build1(rt<<1,l,mid);
	build1(rt<<1|1,mid+1,r);	
	add(t1[rt<<1].id,t1[rt].id,0),add(t1[rt<<1|1].id,t1[rt].id,0);
}
void build2(int rt,int l,int r)
{
	t2[rt].l=l,t2[rt].r=r;
	if(l==r)
	{
		t2[rt].id=l+n;
		add(l+n,l,0);
		return;
	}
	add(t2[rt].id,t1[rt].id,0);
	t2[rt].id=++tot;
	int mid=(l+r)>>1;
	build2(rt<<1,l,mid);
	build2(rt<<1|1,mid+1,r);
	add(t2[rt].id,t2[rt<<1].id,0),add(t2[rt].id,t2[rt<<1|1].id,0);
}
struct node
{
	int num;
	ll val;
	friend bool operator < (node a,node b)
	{
		return a.val>b.val;
	}
}f,ff;
ll d[N];
bool vis[N];
inline void dijkstra()
{
	for(int i=1;i<=tot;++i)d[i]=inf;
	d[1]=0;
	f.num=1,f.val=0;
	priority_queue<node>q;
	while(!q.empty())q.pop();
	q.push(f);
	while(!q.empty())
	{
		f=q.top();
		q.pop();
		if(vis[f.num])continue;
		vis[f.num]=1;
		for(int i=head[f.num];i>0;i=mem[i].next)
		{
			int to=mem[i].to;
			if(d[to]>d[f.num]+mem[i].val)
			{
				d[to]=mem[i].val+d[f.num];
				ff.num=to,ff.val=d[to];
				q.push(ff);
			}
		}
	}
}
void query1(int rt,int l,int r,int pos,ll val)
{
	if(l<=t1[rt].l&&t1[rt].r<=r)
	{
		add(t1[rt].id,pos,val);
		return;
	}
	int mid=(t1[rt].l+t1[rt].r)>>1;
	if(l<=mid)
		query1(rt<<1,l,r,pos,val);
	if(r>mid)
		query1(rt<<1|1,l,r,pos,val);
}
void query2(int rt,int l,int r,int pos)
{
	if(l<=t2[rt].l&&t2[rt].r<=r)
	{
		add(pos,t2[rt].id,0);
		return;
	}
	int mid=(t2[rt].l+t2[rt].r)>>1;
	if(l<=mid)
		query2(rt<<1,l,r,pos);
	if(r>mid)
		query2(rt<<1|1,l,r,pos);
}
int main()
{
	n=read(),m=read();
	int l,r;
	ll val;
	tot=n<<1;
	build1(1,1,n),build2(1,1,n);
//	for(int i=1;i<=tot;++i){cout<<i;for(int j=head[i];j;j=mem[j].next)cout<<"->"<<mem[j].to;cout<<endl;}//	system("pause");
	while(m--)
	{
		l=read(),r=read(),val=read();
		query1(1,l,r,++tot,val);
		query2(1,l,r,tot);
	}
//	for(int i=1;i<=tot;++i){cout<<i;for(int j=head[i];j;j=mem[j].next)cout<<"->"<<mem[j].to;cout<<endl;}
	dijkstra();
//	for(int i=1;i<=tot;++i){if(d[i]==inf)d[i]=-1;cout<<d[i]<<' ';}cout<<endl<<endl;
	cout<<d[n<<1]<<'\n';
	return 0;
}

Compiler output:
/tmp/ccVIdM2b.o: in function `build1(int, int, int)':
a.cc:(.text+0x89): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x92): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x98): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/ccVIdM2b.o
/tmp/ccVIdM2b.o: in function `build2(int, int, int)':
a.cc:(.text+0x1c9): relocation truncated to fit: R_X86_64_PC32 against symbol `t2' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x1ec): relocation truncated to fit: R_X86_64_PC32 against symbol `t2' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x223): relocation truncated to fit: R_X86_64_PC32 against symbol `t2' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x285): relocation truncated to fit: R_X86_64_PC32 against symbol `t2' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x29c): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x2a5): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x2ab): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/ccVIdM2b.o
a.cc:(.text+0x2c8): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status