Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<pair<int, pair<int, int>>> event;
  for (int i = 0; i < N; i++) {
    int s,t,x;
    cin >> s >> t >> x;
    event.push_back(make_pair(s-x, make_pair(1, x)));
    event.push_back(make_pair(t-x, make_pair(-1, x)));
  }
  sort(event.begin(), event.end());
  event.push_back(make_pair(10000000000, make_pair(1, 10000000000)));
  vector<int> pos(Q);
  for (int i = 0; i < Q; i++) {
    int x;
    pos.at(i) = x;
  }
  set<int> S;
  int cnt = 0;
  int m = 10000000000;
  vector<int> ans;
  for (int p : pos) {
    while (event.at(cnt).first <= p) {
      int s, f, x;
      tie(s, f, x) = event.at(cnt);
      cnt++;
      if (f == 1) {
        S.insert(x);
        m = *begin(S);
      }
      else {
        S.erase(x);
        if (m == x) {
          if (S.empty()) {
            m = 10000000000
          }
          else {
            m = *begin(S);
          }
        }
      }
    }
    if (S.empty()) {
      ans.push_back(-1);
    }
    else {
      ans.push_back(m);
    }
  }
  for (int val : ans) {
    cout << val << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:11: warning: overflow in conversion from 'long int' to 'int' changes value from '10000000000' to '1410065408' [-Woverflow]
   23 |   int m = 10000000000;
      |           ^~~~~~~~~~~
a.cc:28:34: error: no match for 'operator=' (operand types are 'std::tuple<int&, int&, int&>' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, std::pair<int, int> > >, std::pair<int, std::pair<int, int> > >::value_type' {aka 'std::pair<int, std::pair<int, int> >'})
   28 |       tie(s, f, x) = event.at(cnt);
      |                                  ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/tuple:1930:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<const _UElements& ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(const std::tuple<_Args1 ...>&) [with _UElements = {_UElements ...}; _Elements = {int&, int&, int&}]'
 1930 |         operator=(const tuple<_UElements...>& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1930:9: note:   template argument deduction/substitution failed:
a.cc:28:34: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, std::pair<int, int> > >, std::pair<int, std::pair<int, int> > >::value_type' {aka 'std::pair<int, std::pair<int, int> >'} is not derived from 'const std::tuple<_UTypes ...>'
   28 |       tie(s, f, x) = event.at(cnt);
      |                                  ^
/usr/include/c++/14/tuple:1940:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<_UElements ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(std::tuple<_Args1 ...>&&) [with _UElements = {_UElements ...}; _Elements = {int&, int&, int&}]'
 1940 |         operator=(tuple<_UElements...>&& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1940:9: note:   template argument deduction/substitution failed:
a.cc:28:34: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, std::pair<int, int> > >, std::pair<int, std::pair<int, int> > >::value_type' {aka 'std::pair<int, std::pair<int, int> >'} is not derived from 'std::tuple<_UTypes ...>'
   28 |       tie(s, f, x) = event.at(cnt);
      |                                  ^
/usr/include/c++/14/tuple:1907:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&>) [with _Elements = {int&, int&, int&}; std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&> = const std::tuple<int&, int&, int&>&]'
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1909:52: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, std::pair<int, int> > >, std::pair<int, std::pair<int, int> > >::value_type' {aka 'std::pair<int, std::pair<int, int> >'} to 'std::__conditional_t<true, const std::tuple<int&, int&, int&>&, const std::__nonesuch&>' {aka 'const std::tuple<int&, int&, int&>&'}
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1908 |                                 const tuple&,
      |                                 ~~~~~~~~~~~~~       
 1909 |                                 const __nonesuch&> __in)
      |                                 ~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/14/tuple:1918:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&>) [with _Elements = {int&, int&, int&}; std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&> = std::tuple<int&, int&, int&>&&]'
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1920:47: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, std::pair<int, int> > >, std::pair<int, std::pair<int, int> > >::value_type' {aka 'std::pair<int, std::pair<int, int> >'} to 'std::__conditional_t<true, std::tuple<int&, int&, int&>&&, std::__nonesuch&&>' {aka 'std::tuple<int&, int&, int&>&&'}
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1919 |                                 tuple&&,
      |                                 ~~~~~~~~       
 1920 |                                 __nonesuch&&> __in)
      |                                 ~~~~~~~~~~~~~~^~~~
a.cc:38:17: warning: overflow in conversion from 'long int' to 'int' changes value from '10000000000' to '1410065408' [-Woverflow]
   38 |             m = 10000000000
      |                 ^~~~~~~~~~~
a.cc:38:28: error: expected ';' before '}' token
   38 |             m = 10000000000
      |                            ^
      |                            ;
   39 |           }
      |           ~