QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#228695 | #6416. Classical Scheduling Problem | lsj2009 | WA | 469ms | 9936kb | C++14 | 2.5kb | 2023-10-28 14:00:51 | 2023-10-28 14:00:51 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define rep(k,l,r) for(int k=l;k<=r;++k)
#define per(k,r,l) for(int k=r;k>=l;--k)
#define cl(f,x) memset(f,x,sizeof(f))
using namespace std;
const int N=2e5+5;
struct SGT {
struct node {
int lson,rson,val,cnt;
}; node tree[N<<2];
#define ls(k) tree[k].lson
#define rs(k) tree[k].rson
int p;
int new_node() {
return ++p;
}
void init() {
rep(i,1,p)
tree[i]={0,0,0,0};
p=0;
}
void push_up(int k) {
tree[k].val=tree[ls(k)].val+tree[rs(k)].val;
tree[k].cnt=tree[ls(k)].cnt+tree[rs(k)].cnt;
}
void update(int &k,int l,int r,int qx,int val) {
if(!k)
k=new_node();
if(l==r) {
tree[k].cnt+=val;
tree[k].val+=val*l;
return;
}
int mid=(l+r)>>1;
if(qx<=mid)
update(ls(k),l,mid,qx,val);
else
update(rs(k),mid+1,r,qx,val);
push_up(k);
}
int query(int k,int l,int r,int rk) {
if(l==r)
return rk*l;
int cnt=tree[ls(k)].cnt,val=tree[ls(k)].val;
int mid=(l+r)>>1;
if(cnt<rk)
return val+query(rs(k),mid+1,r,rk-cnt);
else
return query(ls(k),l,mid,rk);
}
}; SGT pre,suf;
int a[N],b[N],p[N],n,m;
PII t[N];
int check(int x) {
pre.init(); suf.init();
int prt=0,srt=0;
rep(i,1,n)
suf.update(srt,1,1e9,a[i],1);
rep(i,1,n) {
suf.update(srt,1,1e9,a[i],-1);
if(i>=x) {
int k=max(b[i],x);
if(n-i>=k-x) {
if(pre.query(prt,1,1e9,x-1)+suf.query(srt,1,1e9,k-x)+a[i]<=m)
return i;
}
}
pre.update(prt,1,1e9,a[i],1);
}
return -1;
}
void print(int l,int r,int k) {
vector<PII> vec;
rep(i,l,r)
vec.push_back({a[i],p[i]});
sort(vec.begin(),vec.end());
rep(i,0,k-1)
printf("%lld ",vec[i].second);
}
signed main() {
int T;
scanf("%lld",&T);
while(T--) {
scanf("%lld%lld",&n,&m);
rep(i,1,n)
scanf("%lld%lld",&t[i].first,&t[i].second),p[i]=i;
sort(p+1,p+n+1,[](const int &x,const int &y) {
return t[x].second<t[y].second;
});
rep(i,1,n)
a[i]=t[p[i]].first,b[i]=t[p[i]].second;
int l=0,r=n,ans=0,pos=0;
while(l<=r) {
int mid=(l+r)>>1;
int val=check(mid);
if(val!=-1)
ans=mid,pos=val,l=mid+1;
else
r=mid-1;
}
printf("%lld\n%lld\n",ans,max(ans,b[pos]));
if(pos) {
print(1,pos-1,ans-1);
printf("%lld ",p[pos]);
print(pos+1,n,max(ans,b[pos])-ans);
puts("");
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9936kb
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: 469ms
memory: 7944kb
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 21 14 16 3 18 12 9 15 53 53 22 25 37 41 15 27 4 6 48 16 54 5 31 3 38 42 43 44 51 35 20 2 8 30 21 52 19 34 12 7 26 9 53 33 36 46 47 10 24 49 17 40 45 39 13 1 32 23 18 50 11 14 29 12 12 5 12 14 4 6 1 8 7 15 2 9 13 7 14 40 8 41 14 13 1 28 38 21 37 24 11 43 33 10 10 7 12 9 10 29 19 5 28 22 15 0...
result:
wrong answer jury has a better answer: jans = 1, pans = 0 (test case 29)