結果

問題 No.2220 Range Insert & Point Mex
ユーザー no wayno way
提出日時 2023-02-18 12:51:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 176,228 KB
実行使用メモリ 7,020 KB
最終ジャッジ日時 2024-07-21 13:00:05
合計ジャッジ時間 6,185 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct node{
	int l,r,x;
}a[N];
bool operator<(const node&x,const node&y){
	return x.l<y.l;
}
int n,m,x;
int tree[N<<2],sum[N<<2];
void change(int l,int r,int k,int x,int op){
	if (l==r){
		sum[l]+=op;
		if (!sum[l]) tree[k]=l; else tree[k]=N;
	}else{
		int mid=(l+r)/2;
		if (x<=mid) change(l,mid,k<<1,x,op); else change(mid+1,r,k<<1|1,x,op);
		tree[k]=min(tree[k<<1],tree[k<<1|1]);
	}
}
void build(int l,int r,int k){
	if (l==r) tree[k]=l;
	else{
		int mid=(l+r)/2;
		build(l,mid,k<<1); build(mid+1,r,k<<1|1);
		tree[k]=l;
	}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].x);
	sort(a+1,a+n+1);
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
	scanf("%d",&m);
	build(1,n+1,1);
	int l=1;
	for (int i=1;i<=m;i++){
		scanf("%d",&x);
		while (l<=n&&a[l].l<=x){
			if (a[l].x+1<=n) change(1,n+1,1,a[l].x+1,1);
			q.push(make_pair(a[l].r,a[l].x+1));
			l++;
		}
		while (!q.empty()&&q.top().first<x){
			if (q.top().second<=n) change(1,n+1,1,q.top().second,-1);
			q.pop();
		}
		printf("%d\n",tree[1]-1);
	}
}
0