QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408104#6416. Classical Scheduling Problemgrass8cow#Compile Error//C++172.8kb2024-05-09 18:33:392024-05-09 18:33:41

Judging History

你现在查看的是最新测评结果

  • [2024-05-09 18:33:41]
  • 评测
  • [2024-05-09 18:33:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;ll K;
struct qq{
    ll a;int b,id;
}e[201000];
struct SGT{
    ll s1[800100],s2[801000];
    void sc(int p){
        int l=(p<<1),r=(p<<1|1);
        s1[p]=s1[l]+s1[r],s2[p]=s2[l]+s2[r];
    }
    void build(int p,int l,int r,int z){
        if(l==r){
            if(z)s1[p]=1,s2[p]=e[l].a;
            else s1[p]=s2[p]=0;
            return;
        }
        int mid=(l+r)>>1;build(p<<1,l,mid,z),build(p<<1|1,mid+1,r,z);
        sc(p);
    }
    inline void up(int p,int l,int r,int x,int z){
        if(l==r){
            if(z)s1[p]=1,s2[p]=e[l].a;
            else s1[p]=s2[p]=0;
            return;
        }
        int mid=(l+r)>>1;
        if(x<=mid)up(p<<1,l,mid,x,z);
        else up(p<<1|1,mid+1,r,x,z);
        sc(p);
    }
    inline ll kth(int p,int l,int r,int k){
        if(!k)return 0;
        if(l==r)return s2[p];
        int mid=(l+r)>>1;
        if(k<=s1[p<<1])return kth(p<<1,l,mid,k);
        return s2[p<<1]+kth(p<<1|1,mid+1,r,k-s1[p<<1]);
    }
}T[2];
#define pb push_back
vector<int>G[201000];
bool vis[201000];
void sol(){
    scanf("%d%lld",&n,&K);
    for(int i=1;i<=n;i++)scanf("%lld%d",&e[i].a,&e[i].b),vis[i]=0,e[i].id=i,G[i].clear();
    sort(e+1,e+n+1,[&](qq x,qq y){return x.a<y.a;});
    for(int i=1;i<=n;i++)G[e[i].b].pb(i);
    T[0].build(1,1,n,1),T[1].build(1,1,n,0);
    ll ns=0;
    int ans=0,nt=0,all=0;
    for(int i=1;i<=n;i++){
        ns+=e[i].a;if(ns>K)break;
        nt+=(e[i].b<i);
        for(int o:G[i])T[0].up(1,1,n,o,0),T[1].up(1,1,n,o,1),nt+=(o<=i),all++;
        int l=nt,r=min(i,all);
        while(l<=r){
            int mi=(l+r)>>1;
            if(T[0].kth(1,1,n,i-mi)+T[1].kth(1,1,n,mi)<=K)
            ans=max(ans,mi),l=mi+1;
            else r=mi-1;
        }
    }
    printf("%d\n",ans);
    if(!ans){puts("0");return;}
    T[0].build(1,1,n,1),T[1].build(1,1,n,0);
    ns=0,nt=0,all=0;
    for(int i=1;i<=n;i++){
        ns+=e[i].a;if(ns>K)break;
        nt+=(e[i].b<i);
        for(int o:G[i])T[0].up(1,1,n,o,0),T[1].up(1,1,n,o,1),nt+=(o<=i),all++;
        int l=nt,r=min(i,all),jx=-1;
        while(l<=r){
            int mi=(l+r)>>1;
            if(T[0].kth(1,1,n,i-mi)+T[1].kth(1,1,n,mi)<=K)jx=l,l=mi+1;
            else r=mi-1;
        }
        if(jx==ans){
            int st=0;
            for(int j=1;j<=n;j++)
            if(e[j].b<=i&&st<jx)st++,vis[e[j].id]=1;
            assert(st==jx);
            st=0;
            for(int j=1;j<=n;j++)
            if(e[j].b>i&&st<i-jx)st++,vis[e[j].id]=1;
            assert(st==i-jx);
            printf("%d\n",i);`
            for(int j=1;j<=n;j++)if(vis[j])printf("%d ",j);puts("");
            return;
        }
    }
}
int main(){
    int T;scanf("%d",&T);while(T--)sol();
    return 0;
}

詳細信息

answer.code:88:30: error: stray ‘`’ in program
   88 |             printf("%d\n",i);`
      |                              ^
answer.code: In function ‘void sol()’:
answer.code:46:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |     scanf("%d%lld",&n,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~
answer.code:47:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |     for(int i=1;i<=n;i++)scanf("%lld%d",&e[i].a,&e[i].b),vis[i]=0,e[i].id=i,G[i].clear();
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:95:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   95 |     int T;scanf("%d",&T);while(T--)sol();
      |           ~~~~~^~~~~~~~~