Language: C++

/In the name of god
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second

using namespace std;
typedef long long ll;
#define set set1
typedef pair<int,int> pii;
const int maxn = 1e5 + 10;


int ans[maxn];
int pl[maxn];
int segt[4 * maxn];
int f1[4 * maxn],f2[4 * maxn];
bool has[4 * maxn];
inline int lz1(int v,int s,int e,int val){
	f2[v] = 0;
	has[v] = true;
	segt[v] = (e - s) * val;
	f1[v] = val;
}
inline int lz2(int v,int s,int e,int val){
	f2[v] += val;
	segt[v] += (e - s) * val;
}
inline int shift(int v,int s,int e){
	int lc = 2 * v,rc = 2 * v + 1,m = (e + s) / 2;
	if (has[v] != false){
		lz1(lc,s,m,f1[v]);
		lz1(rc,m,e,f1[v]);
		f1[v] = 0;
		has[v] = false;
	}
	if (f2[v] != 0){
		lz2(lc,s,m,f2[v]);
		lz2(rc,m,e,f2[v]);
		f2[v] = 0;
	}
	return 0;
}
int set(int v,int l,int r,int s,int e,int val){
	if ( r<= l) return 0;
	if (s >= r || e <= l) return 0;
	if (s >= l && e <= r){
		lz1(v,s,e,val);
		return 0;
	}
	shift(v,s,e);
	int m = (e + s) / 2;
	set(2 * v,l,r,s,m,val);
	set(2 * v + 1,l,r,m,e,val);
	segt[v] = segt[2 * v] + segt[2 * v + 1];
	return 0;
}
int update(int v,int l,int r,int s,int e,int val){
	if (r <= l) return 0;
	if (s >= r || e <= l) return 0;
	if (s >= l && e <= r){
		lz2(v,s,e,val);
		return 0;
	}
	shift(v,s,e);
	int m = (e + s) / 2;
	update(2 * v,l,r,s,m,val);
	update(2 * v + 1,l,r,m,e,val);
	segt[v] = segt[2 * v] + segt[2 * v + 1];
	return 0;
}
int query(int v,int ind,int s,int e){
	if (ind < s || ind >= e) return 0;
//	cout << v << ' ' << s << ' '  << e << ' ' << segt[v] << endl;
	if (e - s == 1){
		return segt[v];
	}
	shift(v,s,e);
	int m = (e + s) / 2;
	return query(2 * v,ind,s,m) + query(2 * v + 1,ind,m,e);
}
int build(int v,int s,int e){
	f1[v] = f2[v] = 0;
	if (e - s == 1) return 0;
	int m = (e + s) / 2;
	build(2 * v,s,m);
	build(2 * v + 1,m,e);
}
int q,x;
int bs(int lo,int hi,int t,int v){
	int m,found = (t == 0) ?lo - 1:hi + 1;
	while(lo <= hi){
		m = (lo + hi) / 2;
		int as = query(1,m,0,q);
		if (t){
			if (as + v > x){
 				found = m;
				hi = m - 1;
			}else lo = m + 1;
		}else{
			if (as < v){
				found = m;
				lo = m + 1;
			}else hi = m - 1;
		}
	}
	return found;
}
int32_t main(){
	ios_base::sync_with_stdio(0) , cin.tie(0);
	int k;
	cin >> x >> k;
	int r;
	vector<int> swp;
	swp.pb(1e9 + 1);
	for (int i = 0;i < k;i++){
		cin >> r;
		swp.pb(r);
	}
	sort(swp.begin(),swp.end());
	cin >> q;
	int t,a,sz = q - 1;
	vector<pii> qs;
	vector<pii> ts;
	for (int i = 0;i < q;i++){
		cin >> t >>  a;
		qs.pb({a,i});
		ts.pb({-t,i});
	}
	sort(qs.begin(),qs.end());
	sort(ts.begin(),ts.end());
	build(1,0,q);
	for (int i = 0;i < q;i++){
		pl[qs[i].S] = i;
		set(1,i,i + 1,0,q,qs[i].F);
		
	}
	
	int sw = 0,ca;
	int lt = 0;
	for (int i = 0;i < swp.size();i++){
		while(sz >= 0 && -ts[sz].F <= swp[i]){
			ca = query(1,pl[ts[sz].S],0,q);
			int t = -ts[sz].F;
			if (i % 2){
				ca = min(x,ca + (t - lt));
			}else {
				ca = max(0,ca - (t - lt));
			}
			ans[ts[sz].S] = ca;
			sz--;
			ts.pop_back();
		}
		int in = bs(0,q - 1,i % 2,swp[i] - lt);
		if (i % 2){
			set(1,in,q,0,q,x);
			update(1,0,in,0,q,swp[i] - lt);
		}else {
			set(1,0,in + 1,0,q,0);
			update(1,in + 1,q,0,q,-(swp[i] - lt));
		}
	//	cout << in << endl;
	//	for (int i= 0;i < q;i++){
	//		cout << i << ' ' << query(1,i,0,q) << endl;
	///	}
	//	cout << endl << endl << endl;
		lt = swp[i];
	}
	for (int i= 0;i < q;i++){
		cout << ans[i] << '\n';
	}
	return 0;
}


Compiler output:
a.cc:1:1: error: expected unqualified-id before '/' token
    1 | /In the name of god
      | ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:62,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/ext/type_traits.h:164:35: error: 'constexpr const bool __gnu_cxx::__is_null_pointer' redeclared as different kind of entity
  164 |   __is_null_pointer(std::nullptr_t)
      |                                   ^
/usr/include/c++/14/ext/type_traits.h:159:5: note: previous declaration 'template<class _Type> constexpr bool __gnu_cxx::__is_null_pointer(_Type)'
  159 |     __is_null_pointer(_Type)
      |     ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ext/type_traits.h:164:26: error: 'nullptr_t' is not a member of 'std'; did you mean 'nullptr_t'?
  164 |   __is_null_pointer(std::nullptr_t)
      |                          ^~~~~~~~~
In file included from /usr/include/c++/14/cstddef:50,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:41:
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:443:29: note: 'nullptr_t' declared here
  443 |   typedef decltype(nullptr) nullptr_t;
      |                             ^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std'; did you mean 'nullptr_t'?
  666 |     struct is_null_pointer<std::nullptr_t>
      |                                 ^~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:443:29: note: 'nullptr_t' declared here
  443 |   typedef decltype(nullptr) nullptr_t;
      |                             ^~~~~~~~~
/usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid
  666 |     struct is_null_pointer<std::nullptr_t>
      |                                          ^
/usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid
  670 |     struct is_null_pointer<const std::nullptr_t>
      |                                                ^
/usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid
  674 |     struct is_null_pointer<volatile std::nullptr_t>
      |                                                   ^
/usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid
  678 |     struct is_null_pointer<const volatile std::nullptr_t>
      |                                                         ^
/usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
 1429 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/type_traits:1429:57: error: template argument 1 is invalid
 1429 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                                         ^
/usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
 1438 |     : public integral_constant<std::size_t, 0> { };
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/type_traits:1438:46: error: template argument 1 is invalid
 1438 |     : public integral_constant<std::size_t, 0> { };
      |                                              ^
/usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared
 1440 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope
 1441 |     struct rank<_Tp[_Size]>
      |                     ^~~~~
/usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid
 1441 |     struct rank<_Tp[_Size]>
      |                           ^
/usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
 1442 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/type_traits:1442:65: error: template argument 1 is invalid
 1442 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
 1446 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/type_traits:1446:65: error: template argument 1 is invalid
 1446 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:2086:26: error: 'std::size_t' has not been declared
 2086 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/14/type_traits:2087:30: error: '_Size' was not declared in this scope
 2087 |     struct remove_extent<_Tp[_Size]>
      |                              ^~~~~
/usr/include/c++/14/type_traits:2087:36: error: template argument 1 is invalid
 2087 |     struct remove_extent<_Tp[_Size]>
      |                                    ^
/usr/include/c++/14/type_traits:2099:26: error: 'std::size_t' has not been declared
 2099 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/14/type_traits:2100:35: error: '_Size' was not declared in this scope
 2100 |     struct remove_all_extents<_Tp[_Size]>
      |                                   ^~~~~
/usr/include/c++/14/type_traits:2100:41: error: template argument 1 is invalid
 2100 |     struct remove_all_extents<_Tp[_Size]>
      |                                         ^
/usr/include/c++/14/type_traits:2171:12: error: 'std::size_t' has not been declared
 2171 |   template<std::size_t _Len>
      |            ^~~
/usr/include/c++/14/type_traits:2176:30: error: '_Len' was not declared in this scope
 2176 |         unsigned char __data[_Len];
      |                              ^~~~
/usr/include/c++/14/type_traits:2194:12: error: 'std::size_t' has not been declared
 2194 |   template<std::size_t _Len, std::size_t _Align =
      |            ^~~
/usr/include/c++/14/type_traits:2194:30: error: 'std::size_t' has not been declared
 2194 |   template<std::size_t _Len, std::size_t _Align =
      |                              ^~~
/usr/include/c++/14/type_traits:2195:55: error: '_Len' was not declared in this scope
 2195 |            __alignof__(typename __aligned_storage_msa<_Len>::__type)>
      |                                                       ^~~~
/usr/include/c++/14/type_traits:2195:59: error: template argument 1 is invalid
 2195 |            __alignof__(typename __aligned_storage_msa<_Len>::__type)>
      |                                                           ^
/usr/include/c++/14/type_traits:2202:30: error: '_Len' was not declared in this scope
 2202 |         unsigned char __data[_Len];
      |                              ^~~~
/usr/include/c++/14/type_traits:2203:44: error: '_Align' was not declared in this scope
 2203 |         struct __attribute__((__aligned__((_Align)))) { } __align;
      |                                            ^~~~~~
In file included from /usr/include/c++/14/bits/stl_tempbuf.h:59,
                 from /usr/include/c++/14/bits/stl_algo.h:69,
                 from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/new:131:26: error: declaration of 'operator new' as non-function
  131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^~~~~~~~
/usr/include/c++/14/new:131:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                            ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:132:41: error: attributes after parenthesized initializer ignored [-fpermissive]
  132 |   __attribute__((__externally_visible__));
      |                                         ^
/usr/include/c++/14/new:133:26: error: declaration of 'operator new []' as non-function
  133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^~~~~~~~
/usr/include/c++/14/new:133:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                              ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:134:41: error: attributes after parenthesized initializer ignored [-fpermissive]
  134 |   __attribute__((__externally_visible__));
      |