跳到正文

个人记录

1

_lxm约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月24日
更新
2025年12月24日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
struct node{
	int s,t,x;
} c[N];
int n,q,d[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>c[i].s>>c[i].t>>c[i].x;
	}
	for(int i=1;i<=q;i++){
		cin>>d[i];
	}
	sort(c+1,c+1+n,[](node a,node b){
		return a.x<b.x;
	});
	for(int i=1;i<=q;i++){
		int st=d[i];
		int ans=-1;
		for(int j=1;j<=n;j++){
			int now=st+c[j].x;
			if(now>=c[j].s-0.5&&now<=c[j].t-0.5){
				ans=c[j].x;
				break;
			}
		}
		cout<<ans<<'\n';
	}

    return 0;
}
原文