This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int MxN=5e5+10;
int n, a[MxN], b[MxN], cn[MxN];
vi t[4*MxN];
void upd(int p, int x, int l=1, int r=n, int id=1)
{
if(l==r){
t[id].pb(x);
return;
}
int m=(l+r)/2;
if(p<=m) upd(p, x, l, m, id*2);
else upd(p, x, m+1, r, id*2+1);
}
void build(int l=1, int r=n, int id=1)
{
if(l==r) return;
int m=(l+r)/2;
build(l, m, id*2);
build(m+1, r, id*2+1);
int i=0, j=0;
while(true){
if(i<sz(t[id*2]) && j<sz(t[id*2+1])){
if(t[id*2][i]<=t[id*2+1][j]) t[id].pb(t[id*2][i++]);
else t[id].pb(t[id*2+1][j++]);
}
else if(i<sz(t[id*2])) t[id].pb(t[id*2][i++]);
else if(j<sz(t[id*2+1])) t[id].pb(t[id*2+1][j++]);
else break;
}
}
int more_than(int x, vi &vec)
{
int l=0, r=sz(vec);
while(l<r){
int m=(l+r)/2;
if(vec[m]>=x) r=m;
else l=m+1;
}
return sz(vec)-l;
}
int get(int x, int y, int l=1, int r=n, int id=1)
{
if(l>x) return 0;
if(r<=x) return more_than(y, t[id]);
int m=(l+r)/2;
return get(x, y, l, m, id*2)+get(x, y, m+1, r, id*2+1);
}
void init(int N, int A[], int B[]) {
n=N; FOR(i, 0, n) a[i]=A[i], b[i]=B[i];
vector<pii> inf;
FOR(i, 0, n)
{
cn[a[i]]++;
cn[b[i]+1]--;
inf.pb({b[i],a[i]});
}
FOR(i, 1, n+1) cn[i]+=cn[i-1];
sort(inf.begin(), inf.end());
FOR(i, 0, n) upd(inf[i].s, inf[i].f);
build();
}
int can(int m, int k[]) {
sort(k, k+m);
int neg=0;
FOR(i, 0, m)
{
int tot=cn[k[i]]-neg;
if(tot<k[i]) return false;
if(i<m-1){
int same=get(k[i], k[i+1]);
neg=max(0, same-(tot-k[i]));
}
}
return true;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |