제출 #705221

#제출 시각아이디문제언어결과실행 시간메모리
705221bin9638팀들 (IOI15_teams)C++17
0 / 100
91 ms23016 KiB
#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>

ll 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

컴파일 시 표준 에러 (stderr) 메시지

teams.cpp: In function 'int get(int, int)':
teams.cpp:31:30: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   31 |             res+=lis[u].size();
      |                              ^
teams.cpp:34:80: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   34 |         res+=prev(upper_bound(lis[u].begin(),lis[u].end(),pos))-lis[u].begin()+1;
      |                                                                                ^
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:39:15: warning: declaration of 'sl' shadows a global declaration [-Wshadow]
   39 | void init(int sl,int a[],int b[])
      |           ~~~~^~
teams.cpp:12:4: note: shadowed declaration is here
   12 | ll sl[N],n,cnt[N],l[N],r[N];
      |    ^~
teams.cpp:48:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 |         update(l[i],r[i]);
      |                ~~~^
teams.cpp:48:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 |         update(l[i],r[i]);
      |                     ~~~^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:71:13: warning: declaration of 'l' shadows a global declaration [-Wshadow]
   71 |         int l=sz[i],r=n,val,tru=get(sz[i],sz[i]-1);
      |             ^
teams.cpp:12:19: note: shadowed declaration is here
   12 | ll sl[N],n,cnt[N],l[N],r[N];
      |                   ^
teams.cpp:71:21: warning: declaration of 'r' shadows a global declaration [-Wshadow]
   71 |         int l=sz[i],r=n,val,tru=get(sz[i],sz[i]-1);
      |                     ^
teams.cpp:12:24: note: shadowed declaration is here
   12 | ll sl[N],n,cnt[N],l[N],r[N];
      |                        ^
teams.cpp:71:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   71 |         int l=sz[i],r=n,val,tru=get(sz[i],sz[i]-1);
      |                       ^
teams.cpp:83:9: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
   83 |         if(val>=sz[i+1])
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...