QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#228803 | #6416. Classical Scheduling Problem | lsj2009 | RE | 1381ms | 20484kb | C++14 | 2.5kb | 2023-10-28 14:15:15 | 2023-10-28 14:15:16 |
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)+a[i]+suf.query(srt,1,1e9,k-x)<=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=1,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: 1ms
memory: 10192kb
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: 0
Accepted
time: 466ms
memory: 9960kb
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:
ok ok, 10000 test cases (10000 test cases)
Test #3:
score: 0
Accepted
time: 397ms
memory: 10048kb
input:
10000 31 13863446 88657 7 999554 9 118529 26 847277 28 370661 19 261018 28 635679 10 228483 3 645280 9 476021 13 778546 23 325779 9 833392 1 328146 30 873417 6 327100 31 9792 26 327533 31 361518 30 74201 17 220223 12 395716 28 92721 14 296968 27 177176 14 698707 6 130653 14 639654 14 883578 27 94779...
output:
29 30 17 20 1 23 3 27 25 21 8 6 24 12 19 5 22 10 31 7 28 9 26 11 13 4 15 29 30 2 14 16 4 4 2 4 3 5 2 2 1 2 6 7 10 13 25 18 3 17 4 6 6 8 9 10 12 2 5 0 0 13 13 1 9 8 11 13 5 10 2 7 15 4 12 6 7 7 6 3 1 5 8 7 10 12 15 6 21 10 8 12 7 18 5 15 16 9 20 14 3 19 21 24 3 21 16 11 8 14 23 2 4 26 1 15 25...
result:
ok ok, 10000 test cases (10000 test cases)
Test #4:
score: 0
Accepted
time: 416ms
memory: 10200kb
input:
10000 1 148649924 152343597 1 23 2873231053 341227727 2 97244309 22 382344096 18 92079917 18 716353906 4 963429195 14 131618841 1 637584871 10 210001357 11 578579097 4 246465963 6 968391199 2 950133297 8 509339869 18 427327942 11 542440792 6 451945776 11 62800058 4 275583515 14 347078482 12 49062133...
output:
0 0 7 7 18 7 1 16 10 5 11 58 59 10 30 1 40 44 53 28 37 35 34 3 22 61 50 17 38 60 55 29 33 20 2 43 24 56 47 15 49 16 26 31 58 51 27 39 12 52 14 19 4 7 11 25 59 23 46 42 9 21 41 45 62 54 48 5 8 36 6 32 6 7 8 2 4 1 9 14 10 0 0 0 0 8 8 8 3 4 1 9 7 6 2 9 11 16 11 9 24 10 12 4 15 26 21 18 12 12 8 10 ...
result:
ok ok, 10000 test cases (10000 test cases)
Test #5:
score: 0
Accepted
time: 816ms
memory: 11280kb
input:
1000 82 7692098567 820091633 60 355742811 58 33274857 31 608429291 33 997797811 20 467502732 30 853286378 8 652795874 46 342018780 22 758395270 23 273397259 44 363579524 49 911951022 78 19637469 55 648691248 73 289596934 53 538807472 31 612554087 13 925583232 12 934115550 2 348467623 19 793103161 30...
output:
22 31 3 44 70 55 56 30 78 46 76 79 39 9 21 38 24 73 6 72 65 23 18 17 14 81 48 50 69 59 36 33 41 333 336 209 291 121 124 245 155 159 179 200 57 251 132 163 284 119 69 105 268 25 260 206 300 207 117 228 304 127 14 44 281 214 233 108 311 263 294 232 205 59 168 279 140 160 306 248 62 52 314 315 254 246...
result:
ok ok, 1000 test cases (1000 test cases)
Test #6:
score: 0
Accepted
time: 1381ms
memory: 20484kb
input:
100 1903 595649261976 242016788 1493 744829262 608 858593044 1816 156659209 1534 114991300 737 762579703 695 727190226 706 259042985 1281 43413203 314 845442517 462 566008000 1873 396423639 557 642518388 234 224641323 1517 952294191 985 706509300 1598 600896534 1474 40659577 676 385404080 236 626269...
output:
1277 1425 943 573 79 1221 326 496 868 130 555 169 1393 36 1305 650 1588 1784 1873 1017 1893 755 293 309 1106 1219 702 873 525 959 192 569 1228 968 1076 1080 1423 761 1169 1406 1652 859 221 1531 1356 506 581 528 28 1374 1789 1717 587 520 1448 413 1790 955 381 1575 947 1691 1833 1064 129 1719 18 1634 ...
result:
ok ok, 100 test cases (100 test cases)
Test #7:
score: -100
Runtime Error
input:
10 44263 8178145065835 144776695 4988 633784692 681 124897155 10140 486257408 37126 851769386 39526 842969054 41273 255566344 35680 453250390 22330 451088941 12204 619362016 38143 532744479 19473 674895021 28375 9336149 42718 66645534 4600 788583869 43466 74789962 44203 394416695 18040 400692349 209...
output:
18932 24297 17897 4413 4158 14060 43676 19100 21721 8162 30910 39141 14624 21509 31041 28256 29019 32495 27323 38853 13366 27931 28786 20149 11045 10832 23820 11055 38922 20269 30714 5769 22568 37604 19666 36323 21023 27197 34028 44062 10490 16638 20063 27639 20740 16242 6272 43260 22182 5668 260 35...