# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705219 | bin9638 | Teams (IOI15_teams) | C++17 | 95 ms | 23212 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.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fs first
#define sc second
#define N 100010
#define pb push_back
#define ii pair<int,int>
int sl[N],n,cnt[N],l[N],r[N];
vector<int>lis[N];
map<int,int>mp[N];
void update(int u,int val)
{
for(;u<=n;u+=u&(-u))
lis[u].pb(val);
}
int get(int u,int pos)
{
int res=0;
for(;u>0;u-=u&(-u))
{
if(lis[u].empty()||lis[u][0]>pos)
continue;
if(lis[u].back()<=pos)
{
res+=lis[u].size();
continue;
}
res+=prev(upper_bound(lis[u].begin(),lis[u].end(),pos))-lis[u].begin()+1;
}
return res;
}
void init(int sl,int a[],int b[])
{
n=sl;
for(int i=1;i<=n;i++)
{
l[i]=a[i-1];
r[i]=b[i-1];
cnt[l[i]]++;
cnt[r[i]+1]--;
update(l[i],r[i]);
}
for(int i=1;i<=n;i++)
{
cnt[i]+=cnt[i-1];
sort(lis[i].begin(),lis[i].end());
}
}
int can(int m,int sz[])
{
ll sum=0;
sort(sz,sz+m);
for(int i=0;i<m;i++)
sum+=1ll*sz[i],sl[i]=sz[i];
if(sum>n)
return 0;
for(int i=0;i<m;i++)
{
if(cnt[sz[i]]<sl[i])
return 0;
if(i==m-1)
continue;
int l=sz[i],r=n,val,tru=get(sz[i],sz[i]-1);
while(l<=r)
{
int mid=(l+r)/2;
if(get(sz[i],mid)-tru>=sl[i])
{
val=mid;
r=mid-1;
}else
l=mid+1;
}
// cout<<val<<endl;
if(val>=sz[i+1])
{
//cout<<sl[i]<<" "<<-get(sz[i],sz[i+1]-1)<<endl;
sl[i+1]+=(sl[i]-get(sz[i],sz[i+1]-1));
}
}
return 1;
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(NULL);
// cout.tie(NULL);
int n;
cin>>n;
int a[n],b[n];
for(int i=0;i<n;i++)
cin>>a[i]>>b[i];
init(n,a,b);
int q;
cin>>q;
while(q--)
{
int m;
cin>>m;
int k[m];
for(int j=0;j<m;j++)
cin>>k[j];
cout<<can(m,k)<<endl;
}
return 0;
}
#endif // SKY
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |