# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
386810 | cpp219 | Exhibition (JOI19_ho_t2) | C++14 | 233 ms | 11356 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 3e5 + 6;
const ll Log2 = 19;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;
vector<ll> v;
ll n,m,c[N],bit[N],dp[N];
LL a[N];
ll Find(ll x){
return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}
void compress(){
sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
for (ll i = 1;i <= n;i++) a[i].fs = Find(a[i].fs),a[i].sc = Find(a[i].sc);
for (ll i = 1;i <= m;i++) c[i] = Find(c[i]);
}
bool lf(LL x,LL y){
return x.sc < y.sc||(x.sc == y.sc && x.fs < y.fs);
}
void upd(ll p,ll val){
for (ll i = p;i < N;i += i & -i) bit[i] = max(bit[i],val);
}
ll Get(ll p){
ll res = 0;
for (ll i = p;i > 0;i -= i & -i) res = max(res,bit[i]);
return res;
}
/// fs size sc value
bool chk(ll mid){
memset(bit,0,sizeof(bit));
ll start = m - mid + 1;
for (ll i = 1;i <= n;i++){
ll p = Get(a[i].sc) + 1; dp[i] = 0;
if (c[start + p - 1] >= a[i].fs) dp[i] = p;
upd(a[i].sc,dp[i]);
if (dp[i] >= mid) return 1;
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin>>n>>m;
for (ll i = 1;i <= n;i++) cin>>a[i].fs>>a[i].sc,v.push_back(a[i].fs),v.push_back(a[i].sc);
for (ll i = 1;i <= m;i++) cin>>c[i],v.push_back(c[i]); compress();
sort(a + 1,a + n + 1,lf); sort(c + 1,c + m + 1);
ll l,mid,h; //cout<<chk(2); return 0;
l = 0; h = m;
while(l <= h){
mid = (l + h)/2;
if (chk(mid)) l = mid + 1;
else h = mid - 1;
}
cout<<h;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |