QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487117 | #6416. Classical Scheduling Problem | ucup-team1525# | WA | 61ms | 3908kb | C++20 | 3.5kb | 2024-07-22 16:32:27 | 2024-07-22 16:32:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int T,n;
const int N=2000005;
#define ll long long
ll m;
int a[N],b[N],rk[N],rk2[N],cnt;
struct node
{
int ls,rs,sz;
ll v;
}t[N*30];
bool cmp(int x,int y)
{
return b[x]<b[y];
}
bool cmpa(int x,int y)
{
return a[x]==a[y]?b[x]<b[y]:a[x]<a[y];
}
void insert(int x,int l,int r,int p)
{
t[x].sz++;
t[x].v+=p;
if (l==r)
return;
int mid=(l+r)/2;
if (p<=mid)
{
if (!t[x].ls)
t[x].ls=++cnt;
insert(t[x].ls,l,mid,p);
}
else
{
if (!t[x].rs)
t[x].rs=++cnt;
insert(t[x].rs,mid+1,r,p);
}
}
ll ask(int x,int l,int r,int p)
{
if (!x)
return 0;
if (l==r)
return (ll)p*l;
int mid=(l+r)/2;
if (t[t[x].ls].sz>=p)
return ask(t[x].ls,l,mid,p);
else
return ask(t[x].rs,mid+1,r,p-t[t[x].ls].sz)+t[t[x].ls].v;
}
pair<int,ll> ask2(int x,int l,int r,int p)
{
if (!x)
return make_pair(0,0);
if (r<=p)
return make_pair(t[x].sz,t[x].v);
int mid=(l+r)/2;
if (p<=mid)
return ask2(t[x].ls,l,mid,p);
pair<int,ll> tmp=ask2(t[x].rs,mid+1,r,p);
return make_pair(tmp.first+t[t[x].ls].sz,tmp.second+t[t[x].ls].v);
}
ll psum[N];
pair<int,ll> g[N];
int posofrk2[N];
void ins(int x)
{
for (int i=x;i<=n;i+=i&(-i))
{
g[i].first++;
g[i].second+=x;
}
// for (;x<=n;x+=x&(-x))
// ++g[x];
}
pair<int,ll> chk(int x)
{
pair<int,ll> ans;
// int ans=0;
for (;x;x-=x&(-x))
// ans+=g[x];
{
ans.first+=g[x].first;
ans.second+=g[x].second;
}
return ans;
}
vector<int> v[N];
void solve()
{
scanf("%d%lld",&n,&m);
int mx=1;
for (int i=1;i<=n;++i)
v[i].clear();
for (int i=1;i<=n;++i)
{
scanf("%d%d",&a[i],&b[i]);
v[b[i]].push_back(i);
mx=max(mx,a[i]);
rk[i]=i;
rk2[i]=i;
}
sort(rk+1,rk+1+n,cmp);
sort(rk2+1,rk2+1+n,cmpa);
for (int i=1;i<=n;++i)
psum[i]=psum[i-1]+a[rk2[i]];
for (int i=1;i<=n;++i)
posofrk2[rk2[i]]=i;
for (int x=1;x<=cnt;++x)
t[x].ls=t[x].rs=t[x].v=t[x].sz=0;
cnt=1;
int mxp=0,mxsum=0,mxq=0;
for (int p=1;p<=n;++p)
{
for (int i:v[p])
{
insert(1,1,mx,a[i]);
ins(posofrk2[i]);
}
if (psum[p]>m)
break;
int l=0,r=p;
while (l<=r)
{
int mid=(l+r)/2;
// ll ressum=m-psum[mid];
auto q=chk(mid);
if (t[1].sz+mid-q.first>=p)
{
ll o=ask(1,1,mx,p-mid+q.first);
if (o+psum[mid]-q.second<=m)
r=mid-1;
else
l=mid+1;
}
else
l=mid+1;
}
int tmp=p-(l-chk(l).first);
if (tmp>mxsum)
{
mxp=p;
mxsum=tmp;
mxq=l;
}
}
if (mxp==0)
{
puts("0");
puts("0");
puts("");
}
else
{
printf("%d\n",mxsum);
printf("%d\n",mxp);
int k=mxp;
for (int i=1;i<=n&&k;++i)
if (i<=mxq||b[rk2[i]]<=mxp)
{
--k;
printf("%d ",rk2[i]);
}
puts("");
}
}
int main()
{
scanf("%d",&T);
while (T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
2 4 100 20 1 40 4 60 3 30 3 1 5 10 1
output:
2 3 1 4 2 0 0
result:
ok ok, 2 test cases (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 61ms
memory: 3908kb
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:
6 6 21 14 16 3 18 5 53 53 22 25 37 41 15 27 4 6 48 16 54 29 5 31 3 38 42 43 44 51 35 20 2 8 30 21 52 19 34 28 12 7 26 9 53 33 36 46 47 10 49 24 17 40 45 39 13 1 32 23 18 50 11 33 13 5 12 14 16 4 6 1 8 3 11 7 15 10 44 15 38 40 21 37 8 24 28 11 43 33 41 29 26 2 12 55 17 27 16 7 8 12 15 9 18 14 20 ...
result:
wrong answer jury has a better answer: jans = 7, pans = 6 (test case 1)