Language: C++

#include<bits/stdc++.h>
using namespace std;
#define re register
#define ll long long
#define get getchar()
#define in inline
in int read()
{
	int t=0; char ch=get;
	while(ch<'0' || ch>'9') ch=get;
	while(ch<='9' && ch>='0') t=t*10+ch-'0', ch=get;
	return t;
}
const int _=2e5+5;
int n,q,A,B,x[_];
ll lazy[_<<4],min1[_<<4],min2[_<<4];
in void pushdown(int k)
{
	if(lazy[k]==0) return ;
	int x=lazy[k];
	lazy[k]=0;
	lazy[k<<1]+=x;
	lazy[k<<1|1]+=x;
	min1[k<<1]+=x;
	min1[k<<1|1]+=x;
	min2[k<<1]+=x;
	min2[k<<1|1]+=x;
}
in void update(int k,int l,int r,int x,int y)
{
	if(l==r)
	{
		min1[k]=min(min1[k],y-l);
		min2[k]=min(min2[k],y+l);
		return;
	}
	pushdown(k);
	int mid=l+r>>1;
	if(x<=mid) update(k<<1,l,mid,x,y);
	else update(k<<1|1,mid+1,r,x,y);
	min1[k]=min(min1[k<<1],min1[k<<1|1]);
	min2[k]=min(min2[k<<1],min2[k<<1|1]);
}
in int query1(int k,int l,int r,int x,int y)
{
	if(l>=x && r<=y) return min1[k];
	pushdown(k);
	int mid=l+r>>1,minn=0x3f3f3f3f;
	if(x<=mid) minn=min(minn,query1(k<<1,l,mid,x,y));
	if(y>mid) minn=min(minn,query1(k<<1|1,mid+1,r,x,y));
	return minn;
}
in int query2(int k,int l,int r,int x,int y)
{
	if(l>=x && r<=y) return min2[k];
	pushdown(k);
	int mid=l+r>>1,minn=0x3f3f3f3f;
	if(x<=mid) minn=min(minn,query2(k<<1,l,mid,x,y));
	if(y>mid) minn=min(minn,query2(k<<1|1,mid+1,r,x,y));
	return minn;
}
in int getans(int k,int l,int r)
{
	if(l==r) return min1[k]+l;
	pushdown(k);
	int mid=l+r>>1;
	return min(getans(k<<1,l,mid), getans(k<<1|1,mid+1,r));
}
int main()
{
	n=read(),q=read(),A=read(),B=read();
	x[0]=A;
	memset(min1,0x3f,sizeof(min1));
	memset(min2,0x3f,sizeof(min2));
	update(1,1,n,B,0);
	for(re int i=1;i<=q;i++)
	{
		x[i]=read();
		int qwe=min(query1(1,1,n,1,x[i])+x[i],query2(1,1,n,x[i]+1,n)-x[i]);
		lazy[1]+=abs(x[i]-x[i-1]);
		min1[1]+=abs(x[i]-x[i-1]);
		min2[1]+=abs(x[i]-x[i-1]);
		update(1,1,n,x[i-1],qwe);
	}
	cout<<getans(1,1,n);
}


Compiler output:
a.cc: In function 'void update(int, int, int, int, int)':
a.cc:33:28: error: no matching function for call to 'min(long long int&, int)'
   33 |                 min1[k]=min(min1[k],y-l);
      |                         ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:33:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |                 min1[k]=min(min1[k],y-l);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:33:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |                 min1[k]=min(min1[k],y-l);
      |                         ~~~^~~~~~~~~~~~~
a.cc:34:28: error: no matching function for call to 'min(long long int&, int)'
   34 |                 min2[k]=min(min2[k],y+l);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:34:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |                 min2[k]=min(min2[k],y+l);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:34:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |                 min2[k]=min(min2[k],y+l);
      |                         ~~~^~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:76:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   76 |         for(re int i=1;i<=q;i++)
      |                    ^