Language: C++

#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size){
	typedef int32_t rsort_t;
	rsort_t (*a)[size]=base;
	rsort_t (*b)[size]=malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(3<<3))+0x80]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{void *t=a; a=b; b=t;}
	free(b);
}

int s[400000][3];
std::set<int> t;
int main(void){
	int n=nextint();
	int m=nextint();
	for(int i=0; i<n; i++){
		int a=nextint();
		int b=nextint();
		int c=nextint();
		s[i][0]=a-c;
		s[i][1]=1;
		s[i][2]=c;
		s[i+n][0]=b-c;
		s[i+n][1]=-1;
		s[i+n][2]=c;
		//printf(" %d %d %d\n", a-c, b-c, c);
	}
	rsorta_d32(s, n*2, 3);
	int j=0;
	for(int i=0; i<m; i++){
		int d=nextint();
		while(j<2*n && s[j][0]<=d){
			if(s[j][1]>0){
				t.insert(s[j][2]);
				//printf(" push %d %d\n", s[j][0], s[j][2]);
			}else{
				t.erase(s[j][2]);
				//printf(" pop  %d %d\n", s[j][0], s[j][2]);
			}
			j++;
		}
		if(t.empty()){
			puts("-1");
		}else{
			printf("%d\n", *t.begin());
		}
	}
}


Compiler output:
a.cc: In function 'void rsorta_d32(void*, int, int)':
a.cc:24:28: error: invalid conversion from 'void*' to 'rsort_t (*)[size]' {aka 'int (*)[size]'} [-fpermissive]
   24 |         rsort_t (*a)[size]=base;
      |                            ^~~~
      |                            |
      |                            void*
a.cc:25:34: error: invalid conversion from 'void*' to 'rsort_t (*)[size]' {aka 'int (*)[size]'} [-fpermissive]
   25 |         rsort_t (*b)[size]=malloc(count*size*sizeof(rsort_t));
      |                            ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                  |
      |                                  void*
a.cc:27:268: error: invalid conversion from 'void*' to 'rsort_t (*)[size]' {aka 'int (*)[size]'} [-fpermissive]
   27 |         memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{void *t=a; a=b; b=t;}
      |                                                                                                                                                                                                                                                                            ^
      |                                                                                                                                                                                                                                                                            |
      |                                                                                                                                                                                                                                                                            void*
a.cc:28:268: error: invalid conversion from 'void*' to 'rsort_t (*)[size]' {aka 'int (*)[size]'} [-fpermissive]
   28 |         memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{void *t=a; a=b; b=t;}
      |                                                                                                                                                                                                                                                                            ^
      |                                                                                                                                                                                                                                                                            |
      |                                                                                                                                                                                                                                                                            void*
a.cc:29:268: error: invalid conversion from 'void*' to 'rsort_t (*)[size]' {aka 'int (*)[size]'} [-fpermissive]
   29 |         memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{void *t=a; a=b; b=t;}
      |                                                                                                                                                                                                                                                                            ^
      |                                                                                                                                                                                                                                                                            |
      |                                                                                                                                                                                                                                                                            void*
a.cc:30:268: error: invalid conversion from 'void*' to 'rsort_t (*)[size]' {aka 'int (*)[size]'} [-fpermissive]
   30 |         memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(3<<3))+0x80]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{void *t=a; a=b; b=t;}
      |                                                                                                                                                                                                                                                                            ^
      |                                                                                                                                                                                                                                                                            |
      |                                                                                                                                                                                                                                                                            void*