QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#44567 | #4585. Greedy Knapsack | eyiigjkn | RE | 966ms | 204768kb | C++14 | 2.5kb | 2022-08-19 10:33:30 | 2022-08-19 10:33:30 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr double alp=1-1./sqrt(2);
int w[100010],v[100010],stk[5000010],lc[5000010],rc[5000010],sz[5000010],tot=0,cnt=0;
ll len[5000010],val[5000010],addmk[5000010];
bool flag[5000010];
int newnode(int s=0,ll l=0,ll v=0)
{
int cur=(stk[0]?stk[stk[0]--]:++tot);cnt++;
assert(cur<=5000000);
addmk[cur]=lc[cur]=rc[cur]=0;
sz[cur]=s;
len[cur]=l;val[cur]=v;
return cur;
}
int copy(int rt)
{
int cur=(stk[0]?stk[stk[0]--]:++tot);cnt++;
assert(cur<=5000000);
tie(lc[cur],rc[cur],sz[cur],len[cur],val[cur],addmk[cur])=make_tuple(lc[rt],rc[rt],sz[rt],len[rt],val[rt],addmk[rt]);
return cur;
}
void pushup(int rt)
{
if(!lc[rt]) return;
sz[rt]=sz[lc[rt]]+sz[rc[rt]];
len[rt]=len[lc[rt]]+len[rc[rt]];
val[rt]=max(val[lc[rt]],val[rc[rt]]);
}
void update(int rt,ll x)
{
val[rt]+=x;addmk[rt]+=x;
}
void pushdown(int rt)
{
if(addmk[rt])
{
if(lc[rt]) update(lc[rt]=copy(lc[rt]),addmk[rt]);
if(rc[rt]) update(rc[rt]=copy(rc[rt]),addmk[rt]);
addmk[rt]=0;
}
}
int join(int x,int y)
{
int rt=newnode();
lc[rt]=x;rc[rt]=y;
pushup(rt);
return rt;
}
int merge(int x,int y)
{
if(!x || !y) return x+y;
pushdown(x);pushdown(y);
if(min(sz[x],sz[y])>=alp*(sz[x]+sz[y])) return join(x,y);
if(sz[x]>=sz[y])
if(sz[lc[x]]>=alp*(sz[x]+sz[y])) return merge(lc[x],merge(rc[x],y));
else return pushdown(rc[x]),merge(merge(lc[x],lc[rc[x]]),merge(rc[rc[x]],y));
else
if(sz[rc[y]]>=alp*(sz[x]+sz[y])) return merge(merge(x,lc[y]),rc[y]);
else return pushdown(lc[y]),merge(merge(x,lc[lc[y]]),merge(rc[lc[y]],rc[y]));
}
void split(int rt,ll k,int &x,int &y)
{
if(!rt) return x=y=0,void();
if(sz[rt]==1)
if(!k) return x=0,y=rt,void();
else if(k==len[rt]) return x=rt,y=0,void();
else return x=newnode(1,k,val[rt]),y=newnode(1,len[rt]-k,val[rt]),void();
pushdown(rt);
if(k<=len[lc[rt]]) split(lc[rt],k,x,y),y=merge(y,rc[rt]);
else split(rc[rt],k-len[lc[rt]],x,y),x=merge(lc[rt],x);
}
void dfs(int rt)
{
if(!rt || flag[rt]) return;
flag[rt]=1;
dfs(lc[rt]);dfs(rc[rt]);
}
int main()
{
int n,rt;
ll m;
cin>>n>>m;
for(int i=1;i<=n;i++) scanf("%d",&w[i]);
for(int i=1;i<=n;i++) scanf("%d",&v[i]);
rt=newnode(1,m+1,0);
for(int i=n;i;i--)
{
int a,b,c,d;
split(rt,w[i],a,b);
split(rt,m-w[i]+1,c,d);
if(c) update(c,v[i]);
rt=merge(a,c);
if(cnt>4995000)
{
cnt=stk[0]=0;dfs(rt);
for(int i=1;i<=tot;i++)
if(flag[i]) flag[i]=0,cnt++;
else stk[++stk[0]]=i;
}
}
cout<<val[rt]<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 17876kb
input:
5 10 10 1 2 3 4 1 1 1 1 1
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 4ms
memory: 16028kb
input:
5 10000000000 10 1 2 3 4 30 2 15 7 11
output:
65
result:
ok single line: '65'
Test #3:
score: 0
Accepted
time: 2ms
memory: 16032kb
input:
5 20 4 9 5 1 3 203 175 131 218 304
output:
900
result:
ok single line: '900'
Test #4:
score: 0
Accepted
time: 2ms
memory: 17936kb
input:
1 1 1 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 410ms
memory: 204532kb
input:
100000 200000 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100002
result:
ok single line: '100002'
Test #6:
score: 0
Accepted
time: 966ms
memory: 199560kb
input:
92455 883403359 82193 96168 42737 25557 5699 8922 41136 82789 26249 74241 57030 29989 41743 78491 37281 60598 23165 51802 13911 88911 55220 25398 60154 2879 14519 61138 16806 15952 83710 44076 43551 41425 11055 3321 59105 34722 60133 13735 36785 73444 92250 3613 35787 10798 35612 9564 42531 49012 83...
output:
881743221
result:
ok single line: '881743221'
Test #7:
score: 0
Accepted
time: 762ms
memory: 202876kb
input:
95787 282807627 71790 93372 34507 85540 25871 70820 42496 67633 50879 43192 861 57228 54094 91534 94590 24032 52665 82236 52010 45017 15045 76804 39159 72380 28162 89590 31125 21390 37395 34002 26585 2985 90847 12060 63128 73061 34524 61847 69734 53329 39554 90867 13357 18202 63266 44796 64191 40066...
output:
287223570
result:
ok single line: '287223570'
Test #8:
score: 0
Accepted
time: 332ms
memory: 204632kb
input:
100000 100001 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100001
result:
ok single line: '100001'
Test #9:
score: 0
Accepted
time: 423ms
memory: 204620kb
input:
100000 200000 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100002
result:
ok single line: '100002'
Test #10:
score: 0
Accepted
time: 346ms
memory: 204520kb
input:
100000 101603 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100001
result:
ok single line: '100001'
Test #11:
score: 0
Accepted
time: 383ms
memory: 204768kb
input:
100000 200000 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100002
result:
ok single line: '100002'
Test #12:
score: 0
Accepted
time: 308ms
memory: 204096kb
input:
100000 109258 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100001
result:
ok single line: '100001'
Test #13:
score: 0
Accepted
time: 406ms
memory: 204612kb
input:
100000 200000 100000 99997 99994 99991 99988 99985 99983 99980 99977 99974 99972 99969 99966 99963 99961 99958 99955 99952 99950 99947 99944 99942 99939 99936 99933 99930 99928 99926 99923 99920 99917 99914 99912 99909 99906 99904 99901 99899 99897 99894 99891 99889 99886 99883 99881 99879 99876 998...
output:
100003
result:
ok single line: '100003'
Test #14:
score: 0
Accepted
time: 323ms
memory: 204288kb
input:
100000 104441 100000 99997 99994 99991 99988 99985 99983 99980 99977 99974 99972 99969 99966 99963 99961 99958 99955 99952 99950 99947 99944 99942 99939 99936 99933 99930 99928 99926 99923 99920 99917 99914 99912 99909 99906 99904 99901 99899 99897 99894 99891 99889 99886 99883 99881 99879 99876 998...
output:
100002
result:
ok single line: '100002'
Test #15:
score: 0
Accepted
time: 479ms
memory: 204452kb
input:
100000 200000 100000 99993 99987 99978 99972 99965 99960 99954 99948 99944 99941 99931 99929 99919 99910 99904 99894 99888 99877 99871 99863 99858 99852 99850 99843 99839 99829 99823 99812 99807 99795 99791 99780 99774 99766 99755 99750 99742 99731 99725 99718 99711 99702 99696 99693 99689 99678 996...
output:
100002
result:
ok single line: '100002'
Test #16:
score: 0
Accepted
time: 339ms
memory: 203228kb
input:
100000 100220 100000 99993 99987 99978 99972 99965 99960 99954 99948 99944 99941 99931 99929 99919 99910 99904 99894 99888 99877 99871 99863 99858 99852 99850 99843 99839 99829 99823 99812 99807 99795 99791 99780 99774 99766 99755 99750 99742 99731 99725 99718 99711 99702 99696 99693 99689 99678 996...
output:
100001
result:
ok single line: '100001'
Test #17:
score: 0
Accepted
time: 0ms
memory: 18080kb
input:
1 1 2 100000
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 509ms
memory: 202760kb
input:
100000 200000 100000 99991 99969 99958 99945 99932 99930 99912 99899 99891 99875 99857 99845 99830 99814 99802 99783 99766 99754 99733 99729 99726 99713 99696 99675 99665 99646 99642 99625 99621 99612 99605 99590 99585 99569 99566 99559 99552 99543 99528 99513 99497 99485 99478 99476 99457 99435 994...
output:
100003
result:
ok single line: '100003'
Test #19:
score: 0
Accepted
time: 376ms
memory: 201984kb
input:
100000 100012 100000 99991 99969 99958 99945 99932 99930 99912 99899 99891 99875 99857 99845 99830 99814 99802 99783 99766 99754 99733 99729 99726 99713 99696 99675 99665 99646 99642 99625 99621 99612 99605 99590 99585 99569 99566 99559 99552 99543 99528 99513 99497 99485 99478 99476 99457 99435 994...
output:
100002
result:
ok single line: '100002'
Test #20:
score: 0
Accepted
time: 302ms
memory: 199804kb
input:
100000 104768 42198 63876 70289 97679 99129 99383 99678 99811 99998 99999 99999 99999 100000 100000 100000 12433 8169 3583 222 37 35 9 2 1 1 1 1 1 1 1 65163 81308 91468 93404 95453 99894 99909 99998 99999 99999 99999 99999 100000 100000 100000 23740 11045 4364 2504 1858 1225 1157 1071 505 76 5 2 2 2...
output:
45
result:
ok single line: '45'
Test #21:
score: 0
Accepted
time: 291ms
memory: 200196kb
input:
100000 104790 66799 77219 97947 99699 99727 99872 99924 99980 99989 99991 100000 100000 100000 100000 100000 37709 33873 24409 1661 1157 1097 410 252 224 122 94 14 7 4 4 58118 97059 99179 99309 99324 99815 99829 99932 99933 99942 99971 99972 99992 99995 99995 71139 43023 15781 14293 3416 975 325 163...
output:
104790
result:
ok single line: '104790'
Test #22:
score: 0
Accepted
time: 257ms
memory: 201788kb
input:
100000 200000 59927 72467 75688 92437 93614 94992 97911 98151 98487 98938 99612 99947 99956 99995 99999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 ...
output:
632
result:
ok single line: '632'
Test #23:
score: 0
Accepted
time: 255ms
memory: 200236kb
input:
100000 200000 86758 94096 95161 96612 98162 98338 98548 99356 99854 99996 99999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100...
output:
200000
result:
ok single line: '200000'
Test #24:
score: 0
Accepted
time: 185ms
memory: 200520kb
input:
100000 150000 3841 4238 30552 47243 50833 93202 96257 97547 98352 98668 99000 99932 99987 99991 99992 99997 99998 99998 99998 99999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 ...
output:
3855
result:
ok single line: '3855'
Test #25:
score: 0
Accepted
time: 204ms
memory: 201720kb
input:
100000 150000 10723 22346 89189 97960 99966 99968 99969 99985 99994 99994 99997 99997 99997 99999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000...
output:
150000
result:
ok single line: '150000'
Test #26:
score: 0
Accepted
time: 220ms
memory: 204656kb
input:
90108 9829673297 3 3 5 5 5 5 5 7 9 11 13 15 15 17 17 19 20 22 22 22 22 24 25 25 25 27 28 30 30 31 32 34 34 35 35 36 37 38 39 41 42 44 44 46 48 49 49 50 51 52 53 55 55 56 57 59 61 63 65 67 69 70 71 72 72 73 75 76 77 77 78 78 80 80 80 80 81 81 81 81 82 82 82 84 86 87 89 89 90 90 90 90 92 94 95 97 99 1...
output:
4514516167
result:
ok single line: '4514516167'
Test #27:
score: 0
Accepted
time: 247ms
memory: 204220kb
input:
98347 2610706974 3 3 3 5 5 6 6 8 9 9 10 10 12 14 14 15 15 16 16 16 16 18 19 19 21 22 24 25 25 26 27 28 29 29 29 29 31 32 33 35 37 39 40 42 42 43 45 47 48 49 51 52 52 52 52 52 53 55 57 58 59 60 61 62 64 66 66 68 70 71 73 73 73 75 75 75 77 79 79 79 79 79 80 80 82 84 85 85 86 88 90 92 93 94 94 96 97 98...
output:
3635495789
result:
ok single line: '3635495789'
Test #28:
score: 0
Accepted
time: 247ms
memory: 204768kb
input:
100000 10000000000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 1...
output:
10000000000
result:
ok single line: '10000000000'
Test #29:
score: 0
Accepted
time: 248ms
memory: 204324kb
input:
96019 5787043590 2 2 2 4 6 7 9 10 11 11 11 13 15 16 16 18 19 19 19 20 22 22 24 25 27 27 27 29 29 29 29 29 30 31 31 31 33 34 36 36 36 38 39 40 41 42 44 46 48 50 50 50 52 53 55 55 57 57 57 58 59 60 60 61 63 63 63 63 65 67 67 68 68 68 68 70 72 72 72 72 74 74 76 76 78 80 80 82 84 85 87 87 89 89 90 92 93...
output:
4809329210
result:
ok single line: '4809329210'
Test #30:
score: 0
Accepted
time: 261ms
memory: 204428kb
input:
98767 3349493383 3 4 5 6 8 8 8 9 11 13 14 15 15 16 17 18 18 18 20 22 22 22 23 23 23 24 24 24 25 25 25 26 26 28 28 28 30 31 31 31 31 32 33 35 37 39 40 42 44 45 47 47 48 49 51 51 53 54 56 56 57 58 59 61 62 64 66 68 69 71 71 72 74 75 77 79 79 81 83 85 87 87 87 87 87 87 89 90 91 91 92 93 95 95 95 95 97 ...
output:
4094678962
result:
ok single line: '4094678962'
Test #31:
score: 0
Accepted
time: 249ms
memory: 204460kb
input:
94867 3025683990 3 3 4 5 7 9 11 13 14 14 14 15 17 17 17 17 17 18 20 22 22 24 25 25 26 28 30 30 30 31 32 34 35 37 37 37 38 38 38 39 40 41 41 43 43 44 44 45 47 47 48 49 50 52 54 54 55 57 59 61 63 65 66 66 66 67 67 67 68 68 69 69 71 71 71 71 72 74 75 77 79 81 81 81 83 83 84 85 87 88 88 90 91 92 92 92 9...
output:
3908322163
result:
ok single line: '3908322163'
Test #32:
score: 0
Accepted
time: 215ms
memory: 203216kb
input:
91659 246378163 3 3 4 4 6 7 7 9 9 9 11 12 14 15 16 16 16 18 18 20 22 22 24 24 25 25 25 26 27 27 27 27 27 27 29 31 32 33 33 33 34 34 34 35 36 37 37 38 38 38 38 38 40 41 42 43 44 46 46 48 48 48 50 51 52 54 55 57 58 60 61 63 64 66 67 69 70 72 73 74 74 74 74 74 74 74 75 76 76 76 76 78 80 80 81 81 81 81 ...
output:
1111041938
result:
ok single line: '1111041938'
Test #33:
score: 0
Accepted
time: 238ms
memory: 204612kb
input:
99470 1569644496 1 2 4 6 7 7 7 7 8 9 9 11 11 13 14 14 14 16 17 18 19 19 21 21 21 23 23 23 24 25 27 29 29 29 29 31 33 35 36 36 38 39 40 42 43 43 43 43 44 46 47 48 49 50 52 53 54 54 56 56 56 57 58 60 61 63 63 64 65 66 67 68 68 70 71 72 74 75 76 78 78 79 79 81 81 81 82 84 86 87 87 87 89 91 91 92 93 94 ...
output:
2802418185
result:
ok single line: '2802418185'
Test #34:
score: 0
Accepted
time: 227ms
memory: 202908kb
input:
94544 441795869 2 4 5 6 7 7 9 10 11 13 13 15 15 16 16 16 17 18 20 20 20 21 23 24 26 27 29 30 31 32 32 32 34 35 35 35 36 36 37 37 37 37 38 40 42 42 44 45 45 47 48 50 50 51 52 53 53 53 54 55 55 57 59 59 59 61 63 64 66 68 68 70 71 71 73 74 76 78 79 81 81 81 81 81 81 81 83 84 84 86 88 89 91 91 91 93 95 ...
output:
1482081338
result:
ok single line: '1482081338'
Test #35:
score: 0
Accepted
time: 253ms
memory: 204404kb
input:
92132 6712168296 26 43 86 151 166 171 189 190 287 311 323 331 384 430 451 478 506 595 648 708 778 782 789 881 903 930 951 985 1032 1128 1131 1156 1223 1299 1362 1417 1491 1545 1605 1663 1679 1686 1697 1760 1798 1829 1897 1964 2040 2130 2167 2170 2171 2235 2293 2338 2407 2440 2451 2514 2530 2530 2600...
output:
3413719431
result:
ok single line: '3413719431'
Test #36:
score: 0
Accepted
time: 228ms
memory: 204440kb
input:
91775 6146936725 53 70 150 200 214 229 275 329 420 445 524 601 618 649 676 731 811 875 903 956 977 1012 1031 1099 1165 1194 1233 1293 1372 1390 1464 1504 1507 1542 1602 1643 1685 1769 1773 1800 1891 1949 1967 2042 2108 2145 2198 2234 2304 2400 2488 2564 2631 2727 2758 2797 2831 2871 2912 3011 3012 3...
output:
3121995868
result:
ok single line: '3121995868'
Test #37:
score: 0
Accepted
time: 253ms
memory: 203908kb
input:
98065 1361059647 2 92 94 118 123 153 242 307 329 402 478 500 549 643 701 719 774 775 832 864 921 1006 1070 1126 1128 1213 1230 1328 1385 1451 1515 1609 1617 1623 1698 1698 1768 1836 1882 1952 2015 2109 2141 2172 2228 2244 2284 2295 2374 2447 2500 2587 2626 2692 2694 2761 2765 2784 2799 2835 2880 292...
output:
731620721
result:
ok single line: '731620721'
Test #38:
score: 0
Accepted
time: 244ms
memory: 204600kb
input:
97972 2822108786 5 32 65 161 179 180 261 315 350 442 523 604 609 692 791 812 875 917 1001 1039 1082 1177 1195 1288 1317 1415 1499 1565 1573 1642 1661 1715 1803 1819 1828 1923 2002 2024 2101 2165 2215 2283 2334 2391 2466 2472 2476 2551 2561 2616 2627 2642 2735 2772 2867 2892 2913 3005 3044 3084 3102 ...
output:
1464498579
result:
ok single line: '1464498579'
Test #39:
score: 0
Accepted
time: 217ms
memory: 204496kb
input:
100000 9999999999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10...
output:
9999900000
result:
ok single line: '9999900000'
Test #40:
score: -100
Dangerous Syscalls
input:
98412 6566910933 100000 99999 99997 99997 99996 99995 99993 99992 99991 99990 99988 99987 99987 99987 99985 99984 99982 99980 99978 99978 99977 99977 99977 99977 99977 99975 99974 99972 99970 99970 99968 99968 99967 99966 99964 99964 99963 99961 99959 99958 99956 99954 99953 99951 99951 99949 99949 ...