Language: C++

#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
typedef pair<string,P>PP;
#define F first
#define S second
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
 
struct RLUQ{
  struct query{
    int type;//0=empty, 1=set
    int value;
    query(int a=0,int b=0):type(a),value(b) {}
  };
  query s[(1<<22)];
  int t[(1<<22)];
  RLUQ(){
    fill(t,t+(1<<22),INT_MAX);
  }
  void compute(int k,int l,int r){
    query q=s[k];
    s[k].type=0;
    if(q.type==0||r-l==1)return;
    s[k*2+1]=s[k*2+2]=q;  
    t[k*2+1]=t[k*2+2]=q.value;
  }
  void Set(int a,int b,int x,int k=0,int l=0,int r=(1<<21)){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      s[k]=query(1,x);
      t[k]=x;
    }else{
      int m=(l+r)/2;
      Set(a,b,x,k*2+1,l,m);
      Set(a,b,x,k*2+2,m,r);
      t[k]=min(t[k*2+1],t[k*2+2]);
    }
  }
  int Get(int a,int b,int k=0,int l=0,int r=(1<<21)){
    if(b<=l || r<=a)return INT_MAX;
    compute(k,l,r);
    if(a<=l && r<=b){
      return t[k];
    }else{
      int m=(l+r)/2;
      int lv=Get(a,b,k*2+1,l,m);
      int rv=Get(a,b,k*2+2,m,r);
      return min(lv,rv);
    }
  }
};
 
signed main(){
 
  RLUQ seg;
 
  int n,q;
  cin>>n>>q;
  vector<int>Z;
  vector<P2>v;
  r(i,n){
    int s,t,x;
    scanf("%d%d%d",&s,&t,&x);
    s-=x;
    t-=x;
    t--;
    //cout<<s<<' '<<t<<endl;
    s=max(0LL,s);
    if(t<0)continue;
    //cout<<s<<' '<<t<<endl;
    v.push_back(P2(x,P(s,t)));
    Z.push_back(s);
    Z.push_back(t);
    Z.push_back(s+1);
    Z.push_back(t-1);
    Z.push_back(s-1);
    Z.push_back(t+1);
  }
 
  map<int,int>M_nz;
  map<int,int>M_zn;
  sort(Z.begin(),Z.end());
  Z.erase(unique(Z.begin(),Z.end()),Z.end());
  int cnt=0;
  r(i,Z.size()){
    //cout<<' '<<Z[i]<<endl;
    M_zn[cnt]=Z[i];
    M_nz[Z[i]]=cnt;
    cnt++;
  }
 
  vector<P2>SSS;
 
  r(i,v.size()){
    //cout<<v[i].S.F<<' '<<v[i].S.S<<endl;
    int l=M_nz[v[i].S.F];
    int r=M_nz[v[i].S.S];
    int x=v[i].F;
    //cout<<l<<' '<<r<<' '<<x<<endl;
    SSS.push_back(P2(x,P(l,r+1)));
    //seg.Set(l,r+1,x);
  }
 
  sort(SSS.begin(),SSS.end(),greater<P2>());
 
  r(i,SSS.size()){
    int l=SSS[i].S.F;
    int r=SSS[i].S.S;
    int x=SSS[i].F;
    seg.Set(l,r,x);
  }
 
  int MEMO[1200009];
 
  r(i,1200009)MEMO[i]=seg.Get(i,i+1);
 
  r(i,q){
    int x;
    cin>>x;
    int len=lower_bound(Z.begin(),Z.end(),x)-Z.begin();
    int t=*lower_bound(Z.begin(),Z.end(),x);
 
    //cout<<len<<endl;
 
    ///int p=seg.Get(len,len+1);
 
    if(t==x){
      int p=MEMO[len];
 
      if(p==2147483647)cout<<-1<<endl;
      else cout<<p<<endl;
    }
    else if(lower_bound(Z.begin(),Z.end(),x)==Z.end()){
      cout<<-1<<endl;
    }
    else{
      int p=MEMO[len-1];
 
      if(p==2147483647)cout<<-1<<endl;
      else cout<<p<<endl;
      //cout<<seg.Get(len-1,len)<<endl;
    }
    //cout<<endl;
  }
 
 
}

Compiler output:
a.cc: In function 'int main()':
a.cc:72:10: error: no matching function for call to 'max(long long int, int&)'
   72 |     s=max(0LL,s);
      |       ~~~^~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:72:10: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   72 |     s=max(0LL,s);
      |       ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:72:10: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   72 |     s=max(0LL,s);
      |       ~~~^~~~~~~