結果
問題 |
No.2220 Range Insert & Point Mex
|
ユーザー |
|
提出日時 | 2023-02-18 14:34:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,698 bytes |
コンパイル時間 | 2,325 ms |
コンパイル使用メモリ | 214,044 KB |
最終ジャッジ日時 | 2025-02-10 18:50:38 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 21 WA * 15 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} template <class T> struct RangeMex{ const T inf = numeric_limits<T>::max(); set<pair<T,T>> se; RangeMex(){ se.insert(make_pair(-inf,-inf)); se.insert(make_pair(inf,inf)); } void add(T x){ auto id1 = se.lower_bound(make_pair(x+1,x+1)); auto id2 = se.lower_bound(make_pair(x,x)); id2--; pair<T,T> p1 = *id1, p2 = *id2; if (p1.first > x+1 && p2.second < x-1){ se.insert(make_pair(x,x)); } else if (p1.first > x+1){ se.insert(make_pair(p2.first,x)); se.erase(p2); } else if (p2.second < x-1){ se.insert(make_pair(x,p1.second)); se.erase(p1); } else{ se.insert(make_pair(p2.first,p1.second)); se.erase(p1); se.erase(p2); } } void erase(T x){ auto id = se.lower_bound(make_pair(x+1,x+1)); id--; pair<T,T> p = *id; if (p.second < x) return; if (p.first <= x-1) se.insert(make_pair(p.first,x-1)); if (x+1 <= p.second) se.insert(make_pair(x+1,p.second)); se.erase(p); } T mex(int l, int r){ //[l,r)のmex --r; auto id = se.lower_bound(make_pair(l,l)); pair<T,T> p = *id; if (p.first != l){ id--; pair<T,T> p2 = *id; if (p2.second < l) return l; else if (p2.second < r) return p2.second+1; else return -1; } else if (p.second < r) return p.second+1; else return -1; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; vector<tuple<int,int,int>>T; vector<int>A(n); rep(i,n){ int l,r,a; cin>>l>>r>>A[i]; T.push_back(make_tuple(l,-1,i)); T.push_back(make_tuple(r,1,i)); } int q; cin>>q; rep(i,q){ int x; cin>>x; T.push_back(make_tuple(x,0,i)); } sort(all(T)); vector<int>ans(q); RangeMex<int>M; int mex=0; map<int,int>mp; for(auto[x,t,i]:T){ if(t==0){ ans[i]=M.mex(0,1<<30); }else if(t==-1){ M.add(A[i]); }else{ M.erase(A[i]); } } rep(i,q)cout<<ans[i]<<"\n"; }