QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#408090 | #6416. Classical Scheduling Problem | grass8cow# | WA | 88ms | 8604kb | C++17 | 2.7kb | 2024-05-09 18:15:47 | 2024-05-09 18:15:49 |
Judging History
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 int 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+=o;
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");puts("");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+=o;
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;
st=0;
for(int j=1;j<=n;j++)
if(e[j].b>i&&st<i-jx)st++,vis[e[j].id]=1;
printf("%d\n",i);
for(int j=1;j<=n;j++)if(vis[j])printf("%d ",j);puts("");
}
}
}
int main(){
int T;scanf("%d",&T);while(T--)sol();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 8596kb
input:
2 4 100 20 1 40 4 60 3 30 3 1 5 10 1
output:
2 3 1 2 4 0 0
result:
ok ok, 2 test cases (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 88ms
memory: 8604kb
input:
10000 21 1892 174 13 604 15 170 2 413 11 899 2 531 12 651 17 553 9 429 8 837 14 937 12 577 7 532 11 19 2 173 10 165 6 762 15 221 6 945 13 302 19 7 3 54 26066 812 31 432 24 240 37 171 39 204 47 174 30 569 1 467 5 624 42 734 35 907 3 568 23 802 40 991 32 119 13 187 27 739 42 891 14 550 44 374 16 483 1...
output:
7 8 3 9 12 14 15 16 18 21 53 53 1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 12 12 1 2 4 5 6 7 8 12 13 14 15 16 13 1 2 3 4 5 6 7 8 12 13 14 15 16 7 7 15 17 31 40 14 1 8 11 13 14 15 17 21 24 ...
result:
wrong answer actual and declared scores differ: actual = 0, declared = 13 (test case 4)